Appearance
Link an existing account
When a seller already has MOOKHPay, you cannot open a second account for their phone (POST /accounts answers 409 with code 2944). Ask them to link their account to your platform instead. Nothing happens until they approve it in MOOKHPay with their PIN.
| You need | |
|---|---|
A key with accounts:link | |
PLATFORM_ACCOUNT_LINKS_ENABLED on the deployment | Otherwise the routes answer 404 |
How linking goes
- Your server calls
POST /account-linkswith the seller's phone number and the access you ask for. It answers anidand aurl. - You send the seller to
url. They sign in to MOOKHPay with the account for that phone, see your platform's name and what you ask to do, and approve with their PIN. - MOOKHPay sends
account.linkedto your endpoints when the owner approves, with the account id. You can also readGET /account-links/{id}until it readsapprovedorexpired. Once approved, you can use the account like any other.
What you can ask for
| Scope | Lets your platform |
|---|---|
accounts:read | Read the account, its balances and movements, payouts and business account requests |
payments:write | Take payments on the seller's behalf, with a fee |
payouts:write | Pay out the seller's main wallet to the seller |
login_links:write | Make login links for the seller |
Ask for at least one, each at most once. accounts:write cannot be asked for. Asking for a business account for a linked seller needs only accounts:write on your key. Your key's own scopes still decide which routes you can call: asking a seller for payouts:write does not let a key without it pay out.
Create the link
| Body field | Type | Required | Rules |
|---|---|---|---|
phone | string | Yes | E.164 with +: +254 or +256 and 9 digits, in your key's country |
scopes | array of strings | Yes | 1 to 4 of the scopes above, no repeats |
Nothing else is accepted. Send an Idempotency-Key.
sh
curl -X POST https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY" \
-H "Idempotency-Key: link-seller-9120" \
-H "Content-Type: application/json" \
-d '{
"phone": "+254722000111",
"scopes": ["accounts:read", "payments:write", "payouts:write", "login_links:write"]
}'js
const res = await fetch(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}`,
"Idempotency-Key": "link-seller-9120",
"Content-Type": "application/json",
},
body: JSON.stringify({
phone: "+254722000111",
scopes: ["accounts:read", "payments:write", "payouts:write", "login_links:write"],
}),
},
);
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
// Save body.data.id against the seller, then send them to body.data.urlpython
import os
import requests
res = requests.post(
"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links",
headers={
"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}",
"Idempotency-Key": "link-seller-9120",
},
json={
"phone": "+254722000111",
"scopes": ["accounts:read", "payments:write", "payouts:write", "login_links:write"],
},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
# Save body["data"]["id"] against the seller, then send them to body["data"]["url"]php
<?php
$ch = curl_init("https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY"),
"Idempotency-Key: link-seller-9120",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"phone" => "+254722000111",
"scopes" => ["accounts:read", "payments:write", "payouts:write", "login_links:write"],
]),
]);
$body = json_decode(curl_exec($ch), true);
if (!$body["ok"]) {
throw new RuntimeException("{$body['code']}: {$body['description']}");
}
// Save $body["data"]["id"] against the seller, then send them to $body["data"]["url"]json
{
"ok": true,
"description": "Account link",
"data": {
"id": "plr_ke_4a7c1e9b3d5f2a8c6e0b1d3f",
"url": "https://mookhpay.co/connect/approve?c=KE#t=mlr_Qe1…",
"expires_at": "2026-11-20T12:30:04.000Z",
"status": "pending"
}
}The url carries a one-time secret and appears only in this 201 answer. MOOKHPay does not keep it, so send the seller to it straight away and never store or log it. The answer has Cache-Control: no-store.
The same Idempotency-Key and body answer the same link with 200, but with url null, because the address was shown once. If the 201 was lost, ask again with a new Idempotency-Key; that makes a new link. A different body with the same key answers 422 with code 3015. The order of scopes does not matter.
The answer says nothing about the phone
The answer is the same whether or not the phone has a MOOKHPay account. A phone with no account gets a link that nobody can approve, and it reads pending until it expires. This is deliberate: your key cannot be used to find out who has MOOKHPay.
Send the seller to the link
The link lasts 30 minutes. Send the seller to it from inside your app while they are there, or show it to them as a button. The token is in the fragment after #t=, so it is not sent to servers.
On the page, the seller must be signed in to MOOKHPay with a full session (not a login link's view-only visit) on the account whose phone you named. Signed in on any other account, the link reads as not found for them. They see:
- your platform's name and MOOKHPay ID,
- what you ask to do,
- when the request expires,
- whether their account is already linked to your platform.
They approve by entering their PIN. Only a person's account can be linked, and an account already linked to your platform cannot be linked again.
Learn that it was approved
To follow the approval from your own screen, read GET /account-links/{id}:
sh
curl https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links/plr_ke_4a7c1e9b3d5f2a8c6e0b1d3f \
-H "Authorization: Bearer $MOOKHPAY_SECRET_KEY"js
export async function waitForLink(id) {
for (;;) {
const res = await fetch(
`https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links/${id}`,
{ headers: { Authorization: `Bearer ${process.env.MOOKHPAY_SECRET_KEY}` } },
);
const body = await res.json();
if (!body.ok) throw new Error(`${res.status} ${body.code}: ${body.description}`);
if (body.data.status !== "pending") return body.data; // approved or expired
await new Promise((r) => setTimeout(r, 3000));
}
}python
import os
import time
import requests
def wait_for_link(link_id):
while True:
res = requests.get(
f"https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links/{link_id}",
headers={"Authorization": f"Bearer {os.environ['MOOKHPAY_SECRET_KEY']}"},
timeout=30,
)
body = res.json()
if not body["ok"]:
raise RuntimeError(f"{res.status_code} {body['code']}: {body['description']}")
if body["data"]["status"] != "pending":
return body["data"] # approved or expired
time.sleep(3)php
<?php
function waitForLink(string $id): array {
while (true) {
$ch = curl_init("https://payments-ke-staging.mookhpay.co/v1/payments/merchant/account-links/$id");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("MOOKHPAY_SECRET_KEY")],
]);
$body = json_decode(curl_exec($ch), true);
if (!$body["ok"]) {
throw new RuntimeException("{$body['code']}: {$body['description']}");
}
if ($body["data"]["status"] !== "pending") return $body["data"]; // approved or expired
sleep(3);
}
}json
{
"ok": true,
"description": "Account link",
"data": {
"id": "plr_ke_4a7c1e9b3d5f2a8c6e0b1d3f",
"status": "approved",
"account": "acct_ke_e1b7d03a9c5f4628b0a4c7d2",
"expires_at": "2026-11-20T12:30:04.000Z"
}
}status | Meaning |
|---|---|
pending | Not approved yet, and not expired. account is null |
approved | The owner approved it. account is your id for their account |
expired | 30 minutes passed with no approval. Make a new link to ask again |
Note that this read answers id, status, account and expires_at, and not url; the create answers url and not account.
You do not have to poll
MOOKHPay's account events job reads approvals once a minute by default and sends account.linked whether or not you read the link. Its data carries link_id, scopes and approved_at. Polling is still useful while the seller is on the approval page, so your screen can move on as soon as they approve: a read that finds the link approved queues account.linked at once, and the job never sends it a second time to the same endpoint. Stop polling at expires_at.
After linking
A linked account follows the same rules as one you opened, with these differences:
- The owner sees and approves the scopes you ask for. MOOKHPay checks two of them against the grant today: a payout without
payouts:writeand a login link withoutlogin_links:writeanswer403with code3025. Reads and payments check only your key's scopes. GET /transactionsshows its movements only from the moment the owner approved the link. The per-wallet route reads its whole history.- Payouts go to the owner's chosen payout account, or their phone.
- Its limits follow the owner's own verification.
- Its
originislinkedand itsexternal_referenceisnull. - The owner can disconnect your platform at any time. See What sellers see and control.
To ask for more access later, make a new link with the scopes you want. While the account is still linked to your platform the owner sees that it is already linked and cannot approve a second link; they must disconnect first.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | A bad phone, a phone outside this country, an unknown scope, a repeat, or an unknown field | Fix the body |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks accounts:link | Make a key with it |
403 | 2942 | PLATFORM_NOT_ENABLED | Not a platform, or suspended | Ask MOOKHPay |
404 | 3027 | ACCOUNT_LINK_NOT_FOUND | Unknown id, or another platform's | Check the id |
422 | 3015 | IDEMPOTENCY_KEY_REUSED | Same key, different body | Use a new key |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | Links could not be made or read right now | Retry with the same key |