# Electricity API

The Electricity API lets your app check a prepaid meter, buy electricity and retrieve the token for that purchase when it’s ready. The SIMcloud minimum is R11. Save the client reference so you can find the purchase again if the order is pending or the request times out.

[Web guide](https://simcloud.co.za/docs/guide/electricity-api/)

GET /api/electricity.php · POST /api/electricity.php

[API reference](https://simcloud.co.za/api/electricity.html)

## Check meter support

Set SIMCLOUD_METER_NUMBER to the meter you want to check. The API removes spaces and hyphens. Check supported: true, false or null. Null means the municipality could not confirm the meter at that time.

### GET /api/electricity.php

```bash
curl -4 -sS -i "${SIMCLOUD_API_BASE:-https://simcloud.co.za}/api/electricity.php" \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  --get \
  --data-urlencode "meter_number=$SIMCLOUD_METER_NUMBER"
```

HTTP 200 response excerpt

```json
{
  "status": "success",
  "supported": true
}
```

## Place an order and calculate the fee

Send the meter_number, a whole-rand amount from R11 through R1,000, your unique client_reference and the recipient. Orders from R11 through R55 include a fixed R1 fee. Above R55 the fee is amount × 3 / 103, rounded down to whole rand and capped at R10. An R11 order buys R10 of electricity. The example disables the completion SMS with send_sms: false.

### POST /api/electricity.php

```bash
curl -4 -sS -i -X POST "${SIMCLOUD_API_BASE:-https://simcloud.co.za}/api/electricity.php" \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
  "meter_number": "YOUR_METER_NUMBER",
  "amount": 11,
  "client_reference": "DOCS-ELECTRICITY-01",
  "recipient": "YOUR_LOCAL_CELL",
  "send_sms": false
}'
```

HTTP 201 response excerpt

```json
{
  "status": "success",
  "fee": 1,
  "electricity_amount": 10,
  "amount": 11
}
```

> Municipalities can have their own limits. Use a new client_reference for a separate purchase.

## Recover an order whose outcome is unclear

If POST returns HTTP 202 with reconciliation_pending, or the request times out before you receive the result, keep the original client_reference. Replace the example reference with that value and query the same purchase. Poll again while it is pending. A repeated identical purchase request can replay the recorded result for the same reference.

1. HTTP 409 can return reference_conflict, request_in_progress or duplicate_transaction. Check the existing purchase before retrying.
2. If a duplicate response includes retry_after_seconds, it gives the five-minute wait and leaves the outcome of the earlier order to be checked.

### GET /api/electricity.php

```bash
curl -4 -sS -i "${SIMCLOUD_API_BASE:-https://simcloud.co.za}/api/electricity.php" \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  --get \
  --data-urlencode 'client_reference=DOCS-ELECTRICITY-01'
```

HTTP 200 response excerpt

```json
{
  "status": "pending"
}
```

- [Check a pending order in the portal](https://simcloud.co.za/docs/guide/electricity-status/#pending)

## Read order status or PINs

Set SIMCLOUD_ELECTRICITY_ID to order_id. You can also query using client_reference or the municipality’s order_reference_id. A pending response may mean usable PINs are still outstanding. On success, follow the PIN entry order returned with the voucher. Failed and cancelled are terminal results.

### GET /api/electricity.php

```bash
curl -4 -sS -i "${SIMCLOUD_API_BASE:-https://simcloud.co.za}/api/electricity.php" \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  --get \
  --data-urlencode "order_id=$SIMCLOUD_ELECTRICITY_ID"
```

HTTP 200 response excerpt

```json
{
  "status": "pending"
}
```
