Appearance
Buy tokens
Buys electricity for a meter and returns the token.
POST /api/v1/electricity/buy-tokens
Body
| Field | Type | Required | Description |
|---|---|---|---|
meter_number | string | Yes | The meter number: 10 to 14 digits. |
amount | number | Yes | What your customer pays. At least the minimum (5 unless Xash has set another). At most two decimals when the fee is on. |
currency | string | Yes | The wallet to pay from, for example USD. |
reference | string | No, but send it | Your own id for this purchase. Up to 120 characters: letters, digits, :, ., _ and -. Makes the request safe to repeat. |
Example
bash
curl -X POST https://app.xash.co.zw/api/v1/electricity/buy-tokens \
-H "Authorization: Bearer YOUR_SERVER_TOKEN" \
-H "Content-Type: application/json" \
-d '{"meter_number":"01234567890","amount":10,"currency":"USD","reference":"order-2001"}'A purchase waits for the utility and can take 20 seconds or more. If your request times out, or you receive a 502 or 504, repeat it with the same reference.
Response 200: delivered
json
{
"success": true,
"message": "ZESA tokens purchased successfully.",
"data": {
"success": true,
"customer_name": "T EXAMPLE",
"customer_address": "1 EXAMPLE ROAD HARARE",
"meter_number": "01234567890",
"meter_currency": "USD",
"reference": "order-2001",
"kwh": "35.20",
"energy": "USD8.20",
"debt": "USD0.00",
"rea": "USD0.49",
"vat": "USD1.31",
"total_amt": "USD10.00",
"tendered_currency": "USD",
"tendered": "USD10.00",
"date": "19/11/26 10:15",
"tokens": [
{
"token": "00001111222233334444",
"formatted": "0000 1111 2222 3333 4444",
"units": "35.20",
"rate": "0.2330",
"receipt": "EXAMPLE-RECEIPT-0001",
"tax_rate": "15",
"net_amount": "8.20",
"tax_amount": "1.31",
"position": 1
}
],
"id": "00000000-0000-4000-8000-00000000e001",
"name": "Electricity purchase",
"type": "electricity",
"amount": "10.00",
"currency": "USD",
"balance": {
"currency": "USD",
"name": "US Dollar",
"profit_on_hold": "0.300",
"balance": "40.00"
},
"commission": "USD0.30",
"receipt_footer": "Get airtime/bundle on your change from as little as 10 cents.",
"created_at": "2026-11-19T10:15:00+02:00",
"status": "processed",
"provider_reference": "EXAMPLEPROVIDERREF",
"product": "zesa",
"recipient": "01234567890",
"transaction_id": "00000000-0000-4000-8000-00000000e001",
"fulfilment": {
"token": "00001111222233334444",
"units": "35.20",
"tokens": [
{ "token": "00001111222233334444", "units": "35.20" }
]
},
"error_code": null
}
}The fields you need
| Field | Description |
|---|---|
fulfilment.token | The 20-digit token for the customer to enter on the meter. |
fulfilment.units | The kWh bought. |
fulfilment.tokens | Every token issued. A purchase can return more than one, for example when the meter needs a key-change token first. The customer enters them in order. |
reference | Your reference. |
status | processed. |
transaction_id, id | The Xash transaction id. |
provider_reference | The utility-side reference of the sale. |
amount, currency | What your wallet was charged. |
balance, commission | Your wallet after the purchase, and what you earned. |
The receipt fields
The rest is the receipt, for printing: customer_name, customer_address, meter_number, kwh, energy, debt (arrears recovered), rea (rural electrification levy), vat, total_amt, tendered, date, and tokens with a spaced formatted copy of each token.
When a fee applied, the receipt also has total_paid, fee, fee_label and provider_amount, tendered shows what the customer paid, provider_tendered shows what reached the utility, and message ends with the amount paid and the fee. These amounts are strings with the currency code in front, for example "fee": "USD0.50". The receipt has no total_payment: that name is used only by the quote.
A repeat of the same request returns this same answer and does not buy again.
Response 202: not known yet
json
{
"success": false,
"error_code": "OUTCOME_UNKNOWN",
"message": "This purchase is still being confirmed. Do not buy again; check its status with this reference.",
"data": {
"reference": "order-2001",
"status": "unknown",
"provider_reference": null,
"amount": "10.00",
"currency": "USD",
"product": "zesa",
"recipient": "01234567890",
"transaction_id": "00000000-0000-4000-8000-00000000e001",
"fulfilment": null,
"error_code": null,
"created_at": "2026-11-19T10:15:00+02:00"
}
}The utility did not give a clear answer. The money is held. Do not buy again, with this or any other reference: the token may already exist. Check the status with the same reference until it is processed or failed. When it becomes processed, the status answer carries the token in fulfilment.
Failures
A failure means no token was issued and your wallet was not charged, or was refunded. The body has the same shape as the 202 above with "status": "failed" and the code repeated in data.error_code.
| Status | error_code | Meaning |
|---|---|---|
422 | INSUFFICIENT_FUNDS | Your balance is lower than the amount. |
422 | LIMIT_PER_TRANSACTION, LIMIT_DAILY | A spending limit on your server tokens refused the purchase. Nothing was charged. data also carries the limit figures. |
422 | RECIPIENT_INVALID | The meter could not be verified. message gives the reason when the utility supplied one. |
422 | METER_BUSY | Another purchase for this meter is running right now. Wait for it to finish and check it before buying again. |
422 | DUPLICATE_PURCHASE | This meter has an unresolved purchase, or was sold the same amount in the last 10 minutes. That earlier purchase may have been delivered or be held: check it before buying again. |
422 | PROVIDER_REJECTED | The utility refused the sale. Refunded. |
503 | SERVICE_UNAVAILABLE | Electricity sales are paused. Nothing was charged. |
503 | NOT_SENT | The purchase could not be started. Nothing was charged or sent to the utility. |
409 | REFERENCE_CONFLICT | This reference belongs to an earlier purchase for a different meter, amount or currency. That purchase may have been delivered: look it up before buying again. |
422 | none | A field is invalid. Validation error. No purchase was recorded, so the reference is still free. |
A failed reference stays failed. Repeating it returns the same failure. To try the purchase again, send a new reference. DUPLICATE_PURCHASE, METER_BUSY and REFERENCE_CONFLICT are different: see codes that point at an earlier purchase.
Without a reference
The endpoint also works without reference, as it always has. Then a repeat is a new purchase (subject to the duplicate rule), and the status codes do not follow the pattern above. Read them carefully:
| Status | Body | Meaning |
|---|---|---|
200 | The receipt, with data.reference as a short receipt code and data.id as the transaction id. No status, fulfilment or transaction_id; read the token from data.tokens. | Delivered. |
400 | message is one of: not enough balance, service not active, meter already has a purchase in progress, recent or unresolved purchase exists. | Failed. Nothing was charged. |
422 | message and data from the meter check. | The meter could not be verified. Nothing was charged. |
422 | error_code is LIMIT_PER_TRANSACTION or LIMIT_DAILY. | A spending limit on your server tokens refused the purchase. Nothing was charged. |
500 | message starts with Transaction failed and has been refunded. | The utility refused the sale. This is a definite failure, and it was refunded. |
400 | data.status is on_hold and data.reference is the transaction id. | Not known. The money is held. Do not buy again. Find the transaction in history with include_pending. |
Because a 400 can mean either "failed" or "not known" here, an integration without a reference must check for data.status being on_hold. Sending a reference removes this trap.