# Airtime API Documentation

Use the Airtime API when your app needs to send prepaid airtime to a South African mobile number, for example as a staff allowance or a reward. SIMcloud queues the purchase and gives you a request ID you can use to check whether the airtime was delivered.

## Base URL

```text
https://simcloud.co.za/api/airtime.php
```

## Authentication

All API requests require authentication using a Bearer token in the Authorization header:

```http
Authorization: Bearer YOUR_API_TOKEN
```

See the [API conventions](https://simcloud.co.za/api/index.html#conventions) for IPv4, request timeouts, and retries.

## How It Works

1.  Submit an airtime purchase request with `POST`.
2.  SIMcloud queues the request and returns a `request_id`.
3.  Poll the same endpoint with `GET` until the status changes from `queued` or `pending` to a final status.
4.  Only orders that belong to the authenticated account can be queried.
5.  The same MSISDN and amount cannot be ordered again within 5 minutes. Duplicate requests inside that window return `409`.

## Supported Airtime Networks

- `mtn` or `p-mtn`
- `cellc`, `cell-c`, `cell c` or `p-cellc`
- `vodacom` or `p-vodacom`
- `telkom`, `heita` or `p-heita`

## Endpoints

### 1. Place Airtime Order

POST **Content-Type:** application/json

#### Request Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| msisdn | string | Yes | South African mobile number to recharge. |
| network | string | Yes | Network name or internal code such as `mtn` or `p-mtn`. |
| amount | number | Yes | Recharge amount in rand. Must be between 2 and 999. |
| reference | string | Yes | Your own reference for the request. |

Place airtime request fields

#### Example Request

```bash
curl -4 -sS -i -X POST 'https://simcloud.co.za/api/airtime.php' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
    "msisdn": "0821234567",
    "network": "p-mtn",
    "amount": 10.00,
    "reference": "Airtime for John"
}'
```

#### Success Response

```json
{
    "status": "success",
    "message": "Airtime order queued successfully",
    "request_id": 1527245,
    "service": "airtime",
    "msisdn": "+27821234567",
    "network": "p-mtn",
    "amount": 10,
    "reference": "Airtime for John",
    "queue_status": "queued",
    "timestamp": "2026-04-16 16:00:00"
}
```

#### Insufficient Balance Response

```json
{
    "status": "error",
    "message": "Insufficient balance. Please top up your account.",
    "required_balance": 10,
    "available_balance": 4
}
```

#### Duplicate Order Response

```json
{
    "status": "error",
    "message": "An order for the same MSISDN and amount has been placed in the last 5 minutes."
}
```

### 2. Query Airtime Order

GET

#### Query Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| request_id | integer | No | Queue request ID returned by the POST request. |
| orderno | string | No | Platform order number once it has been allocated. |

Check airtime order query parameters

At least one of the two query parameters is required.

#### Example Request

```bash
curl -4 -sS -i 'https://simcloud.co.za/api/airtime.php?request_id=1527245' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN"
```

#### Pending Response

```json
{
    "status": "pending",
    "service": "airtime",
    "request_id": 1527245,
    "msisdn": "+27821234567",
    "network": "p-mtn",
    "amount": 10,
    "reference": "Airtime for John",
    "platform_order_number": 123456789,
    "queue_status": "Order Placed",
    "final_order_id": 1395228,
    "final_order_status": null,
    "error": null,
    "created_at": "2026-04-16 16:00:00",
    "updated_at": "2026-04-16 16:00:40"
}
```

#### Delivered Response

```json
{
    "status": "delivered",
    "service": "airtime",
    "request_id": 1527245,
    "msisdn": "+27821234567",
    "network": "p-mtn",
    "amount": 10,
    "reference": "Airtime for John",
    "platform_order_number": 123456789,
    "queue_status": "Order Placed",
    "final_order_id": 1395228,
    "final_order_status": "delivered",
    "error": "Success",
    "created_at": "2026-04-16 16:00:00",
    "updated_at": "2026-04-16 16:01:30"
}
```

## Statuses

- `queued`: Request is stored locally and waiting to be placed.
- `pending`: Platform order number exists, but final delivery status is not back yet.
- `delivered`: Airtime order completed successfully.
- `failed`: Airtime order failed.

## Error Responses

Airtime errors use `status: error` and `message`. Balance prechecks also return `required_balance` and `available_balance`.

| HTTP Status | Description |
|----|----|
| 400 | Missing or invalid parameters, or insufficient balance. |
| 401 | Unauthorized (invalid or missing token) |
| 404 | Order not found for this account |
| 409 | Duplicate order detected within the 5-minute rule window |
| 405 | Method not allowed. |
| 500 | Could not confirm the order. Check for the original request. |
| 503 | Order queue busy. Check for the original request before retrying. |

Airtime error responses
