Skip to content

Set a payout destination ​

Starts changing where your pocket's payouts go for one account. MOOKHPay texts a six-digit code to the phone number you send. When the person gives the code back to you, Verify a payout destination makes that number the pocket's payout number.

It is the first of two calls, and it changes nothing by itself. Only pocket mode has it: the number is the pocket's own payout number, and payouts from the pocket go there first. The person can also change it in MOOKHPay with their PIN.

Endpoint ​

POST /v1/payments/merchant/accounts/{id}/payout-destination
AuthSecret key, plus a request signature made with your payout signing secret. See How to sign a request
Scopepayouts:write on the key
PlatformYour organisation must be switched on as a platform, with a pocket set up. Calls must come from an address on your allow-list if MOOKHPay set one
Switched onWhere pockets are available: Kenya. Elsewhere the route answers 404

The key is checked with authn on every call, with no 60-second cache.

Headers ​

HeaderRequiredValue
AuthorizationYesBearer mkp_…
Idempotency-KeyYes1 to 128 characters. It is part of the signature. It does not make the call idempotent: every accepted call texts a new code
Content-TypeYesapplication/json
X-Mookh-TimestampYesThe Unix time in seconds, within 300 seconds of MOOKHPay's clock
X-Mookh-SignatureYessha256= and 64 lowercase hex characters. See How to sign a request

Parameters ​

Path

NameTypeRequiredConstraints
idstringYesOne of your account ids

Body. Unknown fields are refused.

NameTypeRequiredConstraints
railstringYesThe host's payout rail: mpesa in Kenya. Another rail is 422 and code 3040
phonestringYesThe number to pay out to, in international form, with or without +: +254712345678. A number the rail cannot pay (in Kenya, anything but 254 and nine digits) is 422 and code 3040

Example request ​

sh
ACCOUNT=acct_ke_9c2f41b07e5d38a6c1f0b294
HOST=https://payments-ke-staging.mookhpay.co
URL_PATH="/v1/payments/merchant/accounts/$ACCOUNT/payout-destination"
KEY="destination-$(date +%s)"
BODY='{"rail":"mpesa","phone":"+254712345678"}'
TS=$(date +%s)
SIG="sha256=$(printf '%s.POST.%s.%s.%s' "$TS" "$URL_PATH" "$KEY" "$BODY" \
  | openssl dgst -sha256 -hmac "$MOOKHPAY_PAYOUT_SECRET" -hex \
  | sed 's/^.* //')"

curl -X POST "$HOST$URL_PATH" \
  -H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
  -H "Idempotency-Key: $KEY" \
  -H "Content-Type: application/json" \
  -H "X-Mookh-Timestamp: $TS" \
  -H "X-Mookh-Signature: $SIG" \
  --data-binary "$BODY"
js
import { createHmac, randomUUID } from "node:crypto";

const BASE = "https://payments-ke-staging.mookhpay.co/v1/payments/merchant";

async function signedPost(route, payload) {
  const url = new URL(`${BASE}${route}`);
  const body = JSON.stringify(payload);
  const idempotencyKey = randomUUID();
  const timestamp = Math.floor(Date.now() / 1000).toString();
  const signature =
    "sha256=" +
    createHmac("sha256", process.env.MOOKHPAY_PAYOUT_SECRET)
      .update(`${timestamp}.POST.${url.pathname}.${idempotencyKey}.`)
      .update(body)
      .digest("hex");
  const res = await fetch(url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
      "Idempotency-Key": idempotencyKey,
      "Content-Type": "application/json",
      "X-Mookh-Timestamp": timestamp,
      "X-Mookh-Signature": signature,
    },
    body,
  });
  return { status: res.status, answer: await res.json() };
}

const { status, answer } = await signedPost(
  "/accounts/acct_ke_9c2f41b07e5d38a6c1f0b294/payout-destination",
  { rail: "mpesa", phone: "+254712345678" },
);
if (!answer.ok) throw new Error(`${status} ${answer.code} ${answer.data?.error}`);
// Keep verification_id with the person's session; ask them for the code.
console.log(answer.data.verification_id, answer.data.expires_at);

Response ​

200 OK with description Code sent.

json
{
  "ok": true,
  "description": "Code sent",
  "data": {
    "verification_id": "pdv_ke_7c3e9a1b0d4f52e8a6b1c093",
    "expires_at": "2026-11-25T09:10:00.000Z"
  }
}

Response fields ​

FieldTypeMeaning
verification_idstringpdv_, the country, _ and 24 hex characters. Send it with the code to Verify a payout destination
expires_atstringISO 8601. Ten minutes from now. After it, the code no longer works

The code is texted to phone and never returned to you. The person has five tries to enter it.

Errors ​

Refusals from the call itself carry the code's name in data.error.

HTTPCodeNameWhenWhat to do
4001701INVALID_REQUEST_DATAThe body is not JSON, a field is missing, unknown or malformed, or Idempotency-Key is missingFix the request
4003014IDENTITY_HEADER_REFUSEDThe request carries a session or identity headerRemove it
4012781API_KEY_INVALIDMissing, malformed, unknown or revoked keyCheck the key
4013021PAYOUT_SIGNATURE_INVALIDThe signature is missing, malformed, wrong or already used, or the timestamp is more than 300 seconds outSee How to sign a request
4032941API_KEY_SCOPE_REQUIREDThe key lacks payouts:writeIssue a key with the scope
4033042API_KEY_IP_NOT_ALLOWEDThe account has allowed addresses and the call came from another addressCall from a listed address
4032942PLATFORM_NOT_ENABLEDYour organisation is not a platform, or its platform is suspendedTalk to MOOKHPay
4033013PLATFORM_IP_NOT_ALLOWEDThe call came from an address not on your platform's allow-listCall from a listed address
4033022PAYOUT_SIGNING_SECRET_MISSINGYour platform has no payout signing secret yetAn Owner makes one in API Integrations
4042943PLATFORM_ACCOUNT_NOT_FOUNDThe account is unknown, another platform's or malformedCheck the id
4093061PLATFORM_ACCOUNT_DISCONNECTEDThe person disconnected your platform in MOOKHPayAsk them to connect again
4093063PLATFORM_POCKET_NOT_READYThe pocket is still being openedRetry in a minute, signed again
4151701INVALID_REQUEST_DATAContent-Type is not application/jsonSend JSON
4223040PLATFORM_PAYOUT_DESTINATION_INVALIDrail is not this host's payout rail, or phone is not a number that rail can payAsk the person for their number again
4223064PLATFORM_POCKET_NOT_SET_UPYour platform has no pocket set upAsk MOOKHPay to set one up
4291804RATE_LIMIT_EXCEEDEDA code was already sent for this account less than a minute ago: data.retry_after is the seconds to wait. Or over the rate limit below: Retry-After and data.retryAfterWait, then call again with a fresh signature
5032741PROVIDER_UNAVAILABLEThe text could not be sent. Nothing was keptRetry shortly
5032782AUTHN_UNAVAILABLEThe key could not be checkedRetry
5033016PLATFORM_ACCOUNTS_UNAVAILABLEThe account or its pocket could not be readRetry

Rate limit ​

One code a minute per account. Separately, 30 requests a minute per platform, shared with Verify a payout destination. Over it: 429, code 1804, with Retry-After and data.retryAfter in seconds.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.