Appearance
Create an account link
Asks the owner of an existing MOOKHPay account to let your platform in. The answer is a MOOKHPay address to send the person to. Nothing happens until they open it signed in to the account whose phone you named, read what you ask for, and approve it with their PIN. The call never tells you whether the phone has a MOOKHPay account. See Link an existing account.
Endpoint
POST /v1/payments/merchant/account-links| Auth | Secret key |
| Scope | accounts:link |
| Platform | Your organisation must be switched on as a platform, and the call must come from an allowed address if MOOKHPay set a list |
| Switched on | Per deployment (PLATFORM_ACCOUNT_LINKS_ENABLED). Where it is off, the route answers 404 |
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer mkp_… |
Idempotency-Key | Yes | 1 to 128 characters. The same key and body return the same link (200, with url null); the same key with a different body is 422 and code 3015 |
Content-Type | Yes | application/json |
Parameters
Body. Unknown fields are refused, including platform_id and user_id.
| Name | Type | Required | Constraints |
|---|---|---|---|
phone | string | Yes | The person's mobile number in E.164: +254 and 9 digits on the Kenya host, +256 and 9 digits on the Uganda host |
scopes | array of strings | Yes | 1 to 4 distinct values from accounts:read, payments:write, payouts:write and login_links:write. What you ask the person to let your platform do. Order does not matter |
accounts:write cannot be asked for. A business account request for a claimed linked account needs only your key's accounts:write; the account's grant is not checked for it.
Example request
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-3107" \
-H "Content-Type: application/json" \
-d '{
"phone": "+254712345678",
"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-3107",
"Content-Type": "application/json",
},
body: JSON.stringify({
phone: "+254712345678",
scopes: ["accounts:read", "payments:write", "payouts:write", "login_links:write"],
}),
},
);
const answer = await res.json();
if (!answer.ok) throw new Error(`${res.status} ${answer.code}: ${answer.description}`);
const { id, url, expires_at } = answer.data;
console.log(id, url, expires_at);python
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-3107",
},
json={
"phone": "+254712345678",
"scopes": ["accounts:read", "payments:write", "payouts:write", "login_links:write"],
},
timeout=30,
)
answer = res.json()
if not answer["ok"]:
raise RuntimeError(f"{res.status_code} {answer['code']}: {answer['description']}")
print(answer["data"]["id"], answer["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_POSTFIELDS => json_encode([
'phone' => '+254712345678',
'scopes' => ['accounts:read', 'payments:write', 'payouts:write', 'login_links:write'],
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('MOOKHPAY_SECRET_KEY'),
'Idempotency-Key: link-seller-3107',
'Content-Type: application/json',
],
]);
$answer = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (!$answer['ok']) {
throw new RuntimeException("{$status} {$answer['code']}: {$answer['description']}");
}
echo $answer['data']['id'], ' ', $answer['data']['url'], PHP_EOL;Response
201 Created with description Account link when the link is made. 200 OK when the same Idempotency-Key and body already made it; that answer has url null, because the address carries a one-time secret that MOOKHPay shows once and does not keep. If the 201 was lost, make a new link with a new Idempotency-Key. Both answers carry Cache-Control: no-store.
json
{
"ok": true,
"description": "Account link",
"data": {
"id": "plr_ke_5e0c7a2b9d41f3e8a6c1b047",
"url": "https://mookhpay.co/connect/approve?c=KE#t=mlr_Vb7Qx2Lr9Tn4Pz0Kc6Wm1Ys8Hd3Gf5Ja2Ue7Io9Rq4x",
"expires_at": "2026-11-20T09:30:00.000Z",
"status": "pending"
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
id | string | The link request: plr_, the country, _ and 24 hex characters. Pass it to Retrieve an account link |
url | string or null | The address to send the person to: MOOKHPay's /connect/approve page with a one-time token after #t=. Present only on the 201; null on a replay. Hand it to the person at once (your own app, a message or a QR code) and never store or log it |
expires_at | string | ISO 8601, UTC. 30 minutes after the link was made. After it the link does nothing |
status | string | pending for a new link. On a replay: expired after expires_at, and approved once MOOKHPay has recorded the approval (through the account events job or a read of the link) |
What happens at the address:
- The person signs in to MOOKHPay with their own account. Only an account whose phone is the one you sent, and that is a person's account, can open the request; any other account sees nothing.
- They see your platform's name and the access you asked for.
- They approve with their PIN. An account already linked to your platform cannot be linked again.
When they approve, MOOKHPay sends account.linked to your endpoints, with data { link_id, scopes, approved_at }, whether or not you read the link. Retrieve an account link shows the same approval if you want to follow it from your own screen.
Errors
| HTTP | Code | Name | When | What to do |
|---|---|---|---|---|
400 | 1701 | INVALID_REQUEST_DATA | A field is missing, unknown or malformed; scopes is empty, repeats a value or names another scope; Idempotency-Key is missing; or phone is not in this host's country (phone must be a number in this cluster's country) | 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 |
403 | 2941 | API_KEY_SCOPE_REQUIRED | The key lacks accounts:link | 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 |
422 | 3015 | IDEMPOTENCY_KEY_REUSED | The key was used with a different phone or scopes | Use a new key |
429 | 1804 | RATE_LIMIT_EXCEEDED | Over the rate limit | Wait Retry-After seconds |
503 | 2782 | AUTHN_UNAVAILABLE | The key could not be checked | Retry with the same key and body |
503 | 3016 | PLATFORM_ACCOUNTS_UNAVAILABLE | The link could not be made | Retry with the same key and body |
Rate limit
120 requests a minute, shared by every account, balance, transaction, payout read, account link and business account request route your platform calls. Over it: 429, code 1804, with Retry-After and data.retryAfter in seconds.