Appearance
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| Auth | Secret key, plus a request signature made with your payout signing secret. See How to sign a request |
| Scope | payouts:write on the key |
| Platform | Your 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 on | Where pockets are available: Kenya. Elsewhere the route answers 404 |
The key is checked with authn on every call, with no 60-second cache.
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_… |
Idempotency-Key | Yes | 1 to 128 characters. It is part of the signature. It does not make the call idempotent: every accepted call texts a new code |
Content-Type | Yes | application/json |
X-Mookh-Timestamp | Yes | The Unix time in seconds, within 300 seconds of MOOKHPay's clock |
X-Mookh-Signature | Yes | sha256= and 64 lowercase hex characters. See How to sign a request |
Parameters
Path
| Name | Type | Required | Constraints |
|---|---|---|---|
id | string | Yes | One of your account ids |
Body. Unknown fields are refused.
| Name | Type | Required | Constraints |
|---|---|---|---|
rail | string | Yes | The host's payout rail: mpesa in Kenya. Another rail is 422 and code 3040 |
phone | string | Yes | The 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
| Field | Type | Meaning |
|---|---|---|
verification_id | string | pdv_, the country, _ and 24 hex characters. Send it with the code to Verify a payout destination |
expires_at | string | ISO 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.
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | The body is not JSON, a field is missing, unknown or malformed, or Idempotency-Key is missing | Fix the request |
400 | 3014 | IDENTITY_HEADER_REFUSED | The request carries a session or identity header | Remove it |
401 | 2781 | API_KEY_INVALID | Missing, malformed, unknown or revoked key | Check the key |
401 | 3021 | PAYOUT_SIGNATURE_INVALID | The signature is missing, malformed, wrong or already used, or the timestamp is more than 300 seconds out | See How to sign a request |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks payouts:write | Issue a key with the scope |
403 | 3042 | API_KEY_IP_NOT_ALLOWED | The account has allowed addresses and the call came from another address | Call from a listed address |
403 | 2942 | PLATFORM_NOT_ENABLED | Your organisation is not a platform, or its platform is suspended | Talk to MOOKHPay |
403 | 3013 | PLATFORM_IP_NOT_ALLOWED | The call came from an address not on your platform's allow-list | Call from a listed address |
403 | 3022 | PAYOUT_SIGNING_SECRET_MISSING | Your platform has no payout signing secret yet | An Owner makes one in API Integrations |
404 | 2943 | PLATFORM_ACCOUNT_NOT_FOUND | The account is unknown, another platform's or malformed | Check the id |
409 | 3061 | PLATFORM_ACCOUNT_DISCONNECTED | The person disconnected your platform in MOOKHPay | Ask them to connect again |
409 | 3063 | PLATFORM_POCKET_NOT_READY | The pocket is still being opened | Retry in a minute, signed again |
415 | 1701 | INVALID_REQUEST_DATA | Content-Type is not application/json | Send JSON |
422 | 3040 | PLATFORM_PAYOUT_DESTINATION_INVALID | rail is not this host's payout rail, or phone is not a number that rail can pay | Ask the person for their number again |
422 | 3064 | PLATFORM_POCKET_NOT_SET_UP | Your platform has no pocket set up | Ask MOOKHPay to set one up |
429 | 1804 | RATE_LIMIT_EXCEEDED | A 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.retryAfter | Wait, then call again with a fresh signature |
503 | 2741 | PROVIDER_UNAVAILABLE | The text could not be sent. Nothing was kept | Retry shortly |
503 | 2782 | AUTHN_UNAVAILABLE | The key could not be checked | Retry |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | The account or its pocket could not be read | Retry |
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.