# Data API Documentation

Your app can offer South African mobile data bundles through the Data API. Look up the bundles available for the recipient’s network, order the selected bundle and use the request ID from SIMcloud to check delivery.

## Base URL

```text
https://simcloud.co.za/api/data.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.  Fetch the current data product catalogue with `GET`.
2.  Submit a data purchase request with `POST` using one of the returned `network` and `amount` combinations.
3.  SIMcloud queues the request and returns a `request_id`.
4.  Poll the same endpoint with `GET` until the status changes from `queued` or `pending` to a final status.
5.  Only orders that belong to the authenticated account can be queried.
6.  The same MSISDN and amount cannot be ordered again within 5 minutes. Duplicate requests inside that window return `409`.

## Supported Data Networks

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

## Data Bundle Validation

The amount must match a valid bundle sell value configured in SIMcloud for the selected network. Use the product catalogue call before ordering if you need the current available bundle list.

## Endpoints

### 1. List Data Products

GET

Returns data bundle products currently configured for API ordering. Without query parameters, `GET` returns all data products. Add `network` to filter the catalogue.

#### Query Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| network | string | No | Optional network name or internal code such as `mtn` or `pd-mtn`. |

List data products query parameters

#### Example Request

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

```bash
curl -4 -sS -i 'https://simcloud.co.za/api/data.php?products=1&network=mtn' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN"
```

#### Success Response

```json
{
    "status": "success",
    "service": "data",
    "count": 2,
    "products": [
        {
            "product_id": 18,
            "network": "pd-mtn",
            "network_name": "MTN",
            "description": "1GB-R85",
            "groupname": "30-day Data Bundle",
            "amount": 85,
            "sellvalue": 85
        }
    ]
}
```

### 2. Place Data 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 `pd-mtn`. |
| amount | number | Yes | Bundle sell value configured for that network. |
| reference | string | Yes | Your own reference for the request. |

Place data order request fields

The API also accepts `sellvalue` as an alias for `amount`.

#### Example Request

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

#### Success Response

```json
{
    "status": "success",
    "message": "Data order queued successfully",
    "request_id": 1527246,
    "service": "data",
    "msisdn": "+27821234567",
    "network": "pd-mtn",
    "amount": 25,
    "reference": "Data for John",
    "queue_status": "queued",
    "timestamp": "2026-04-16 16:05:00"
}
```

#### Insufficient Balance Response

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

#### Duplicate Order Response

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

### 3. Query Data 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 data order query parameters

At least one of the two query parameters is required to query an order. Without `request_id` or `orderno`, `GET` returns the product catalogue.

#### Example Request

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

#### Delivered Response

```json
{
    "status": "delivered",
    "service": "data",
    "request_id": 1527246,
    "msisdn": "+27821234567",
    "network": "pd-mtn",
    "amount": 25,
    "reference": "Data for John",
    "platform_order_number": 2233445566,
    "queue_status": "Order Placed",
    "final_order_id": 1395229,
    "final_order_status": "delivered",
    "error": "Success",
    "created_at": "2026-04-16 16:05:00",
    "updated_at": "2026-04-16 16:06:20"
}
```

## 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`: Data order completed successfully.
- `failed`: Data order failed.

## Error Responses

Data 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. |

Data error responses
