# API introduction

> Base URL, authentication, responses, errors, pagination and limits.

The Morzepay API lets you collect mobile money, send payouts, run wallets for your own customers, and create invoices and checkout pages from your own code. It is a REST API: you send JSON over HTTPS, and every answer is JSON.

### Base URL

Base URL

```text
https://morzepay.com/v1
```

The same URL serves test and live. Your API key decides which one a request uses.

### Authentication

Every request needs an API key, sent as a bearer token:

Header

```http
Authorization: Bearer mp_test_3f9a1c0b2e7d_9b1c...
```

Create keys under **Developers** in the dashboard. See [Create an API key](https://morzepay.com/docs/api/keys). A key belongs to one business and works only on its test side (`mp_test_…`) or its live side (`mp_live_…`). Keys made before the rename start with `tp_`; they keep working.

Anyone who has a key can use it. Keep keys on your server. Never put one in a website, a mobile app, a public repository or a forum post. If a key leaks, revoke it in the dashboard at once.

#### Permissions

Each key can only do what you allowed when you created it. A request without the needed permission returns `403 INSUFFICIENT_SCOPE`.

| Permission | Allows |
| wallets:read | List wallets, see balances, quote fees |
| wallets:write | Create sub-wallets |
| deposits:write | Collect payments |
| payouts:write | Send payouts |
| transfers:write | Move money between wallets |
| transactions:read | See transactions and receipts |
| msisdn:validate | Look up the name on a phone number |
| invoices:read, invoices:write | See invoices; create, send and change them |
| checkout:read, checkout:write | See checkout sessions; create and expire them |

### Requests

Send `POST` bodies as JSON, with this header:

Header

```http
Content-Type: application/json
```

Amounts are whole Ugandan shillings as numbers: `5000`, not `"5000"` or `5000.5`. Phone numbers can be written `+256771234567`, `256771234567` or `0771234567`; we always return them as `+256…`.

### Responses

A successful answer:

Success

```json
{
  "success": true,
  "data": {
    "id": "wal_Zq4Hn8YtV2kPm6RbX3cLw9",
    "balance": "48500.00",
    "…": "…"
  }
}
```

An error:

Error

```json
{
  "success": false,
  "error": {
    "code": "INSUFFICIENT_FUNDS",
    "message": "The wallet cannot cover the payout plus the estimated mobile money fee.",
    "details": {
      "available": "3000.00",
      "required": "5800.00"
    }
  },
  "request_id": "req_6f1d0c2b9a8e7d6c5b4a"
}
```

| Field | Type | In | Meaning |
| success | boolean | both | true or false. |
| data | object | success | The result: one object, or a list (see Pagination). |
| error.code | string | error | What went wrong. Codes don’t change, so match on them. |
| error.message | string | error | A sentence for people. It can change; don’t match on it. |
| error.details | object | error | Extra facts, such as field for a validation error. |
| request_id | string | error | Send it to support when you report a problem. Every response also has it in the X-Request-Id header. |

Money is returned as text with two decimals, such as `"10363.00"`, because network fees can include fractions. Dates are ISO 8601 in East Africa Time, such as `2026-10-04T14:20:11+03:00`. Every object has `livemode`.

### Errors

| Status | Code | Meaning |
| 400 | INVALID_JSON | The body isn’t valid JSON, or isn’t a JSON object. |
| 401 | UNAUTHENTICATED, KEY_REVOKED | The key is missing, wrong, revoked or expired. |
| 402 | INSUFFICIENT_FUNDS | The wallet can’t cover the amount and fees. Nothing was sent. |
| 403 | INSUFFICIENT_SCOPE | The key doesn’t have the permission this needs. |
| 403 | IP_NOT_ALLOWED | The request came from an address not on the key’s allowlist. |
| 403 | LIVE_NOT_ENABLED | Your business isn’t verified for live payments yet. |
| 403 | BUSINESS_SUSPENDED | The business account is suspended. Contact support. |
| 403 | WEEKLY_LIMIT_REACHED | The payout would go over your 7-day limit. details.remaining shows what’s left. |
| 404 | NOT_FOUND, WALLET_NOT_FOUND | It doesn’t exist, or this key can’t see it. |
| 409 | DUPLICATE_REFERENCE | You already used this reference. The existing transaction_id is in details. |
| 409 | WALLET_NOT_ACTIVE | The wallet is frozen. |
| 409 | IDEMPOTENCY_IN_PROGRESS | A request with the same Idempotency-Key is still running. Wait and retry. |
| 422 | VALIDATION_ERROR | A field is missing or wrong. details.field names it. |
| 422 | MODE_MISMATCH | You mixed test and live, such as a live key and a test wallet. |
| 422 | IDEMPOTENCY_MISMATCH, INVALID_IDEMPOTENCY_KEY | The Idempotency-Key was used with a different body, or isn’t 8–80 letters, digits, - or _. |
| 429 | RATE_LIMITED, MSISDN_RATE_LIMITED | Too many requests. Wait details.retry_after_seconds. |
| 500 | SERVER_ERROR | Something failed on our side. Retry with the same Idempotency-Key. |

### Pagination

List endpoints return a page of results, newest first:

A list

```json
{
  "success": true,
  "data": {
    "items": [
      "…"
    ],
    "has_more": true
  }
}
```

| Parameter | Type | Meaning |
| limit | integer | How many items a page holds, 1 to 100. The default is 25 (50 for wallets). |
| starting_after | string | The id of the last item you have. You get the items after it. |

To get every page, repeat the request with `starting_after` set to the last item’s `id` while `has_more` is `true`.

### Idempotency

Networks fail. To retry a `POST` safely, send an `Idempotency-Key` header:

Header

```http
Idempotency-Key: order-77812
```

- Use a new value, 8 to 80 letters, digits, `-` or `_`, for each thing you want to do. Your order id works well.

- If you send the same key and body again, you get the first answer back with an `Idempotent-Replayed: true` header. Money is never moved twice.

- The same key with a different body returns `422 IDEMPOTENCY_MISMATCH`.

- Keys are remembered for 24 hours. Errors from our side (5xx) and `429` aren’t stored, so you can retry them.

Money-moving requests also need your own unique `reference`, 8 to 36 characters. A second request with the same reference returns `409 DUPLICATE_REFERENCE`, which protects you even without an idempotency key.

### Rate limits

Each API key can make **120 requests a minute**. Past that, the API answers `429 RATE_LIMITED` with a `Retry-After` header.

Separately, the mobile networks allow at most **5 payment requests per phone number every 10 minutes**. A sixth returns `429 MSISDN_RATE_LIMITED` with `details.retry_after_seconds`. Show your customer when they can try again, rather than retrying in a loop. Phone number lookups are limited to 30 a minute per key.

### Versioning

The API version is `v1`, and it is part of every path. We may add endpoints, fields and webhook events to `v1` without notice, so ignore fields you don’t know. A change that could break your code comes in a new version, announced in the [changelog](https://changelog.morzepay.com), and `v1` keeps working for a period we state in the announcement.
