Skip to content

Buy tokens ​

Buys electricity for a meter and returns the token.

POST /api/v1/electricity/buy-tokens

Body ​

FieldTypeRequiredDescription
meter_numberstringYesThe meter number: 10 to 14 digits.
amountnumberYesWhat your customer pays. At least the minimum (5 unless Xash has set another). At most two decimals when the fee is on.
currencystringYesThe wallet to pay from, for example USD.
referencestringNo, but send itYour 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 ​

FieldDescription
fulfilment.tokenThe 20-digit token for the customer to enter on the meter.
fulfilment.unitsThe kWh bought.
fulfilment.tokensEvery 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.
referenceYour reference.
statusprocessed.
transaction_id, idThe Xash transaction id.
provider_referenceThe utility-side reference of the sale.
amount, currencyWhat your wallet was charged.
balance, commissionYour 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.

Statuserror_codeMeaning
422INSUFFICIENT_FUNDSYour balance is lower than the amount.
422LIMIT_PER_TRANSACTION, LIMIT_DAILYA spending limit on your server tokens refused the purchase. Nothing was charged. data also carries the limit figures.
422RECIPIENT_INVALIDThe meter could not be verified. message gives the reason when the utility supplied one.
422METER_BUSYAnother purchase for this meter is running right now. Wait for it to finish and check it before buying again.
422DUPLICATE_PURCHASEThis 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.
422PROVIDER_REJECTEDThe utility refused the sale. Refunded.
503SERVICE_UNAVAILABLEElectricity sales are paused. Nothing was charged.
503NOT_SENTThe purchase could not be started. Nothing was charged or sent to the utility.
409REFERENCE_CONFLICTThis 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.
422noneA 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:

StatusBodyMeaning
200The 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.
400message 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.
422message and data from the meter check.The meter could not be verified. Nothing was charged.
422error_code is LIMIT_PER_TRANSACTION or LIMIT_DAILY.A spending limit on your server tokens refused the purchase. Nothing was charged.
500message starts with Transaction failed and has been refunded.The utility refused the sale. This is a definite failure, and it was refunded.
400data.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.