# SMS API Documentation

The SMS API lets your app send order updates, reminders and other texts to South African mobile numbers. SIMcloud queues each message and gives you an ID so you can check delivery later.

## Base URL

```text
https://simcloud.co.za/api/sms.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.

## Endpoints

### 1. Send SMS

Send a new SMS message to a recipient.

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

#### Request Parameters

| Parameter | Type | Required | Description |
|----|----|----|----|
| recipient | string | Yes | Phone number in South African format (+27XXXXXXXXX) |
| message | string | Yes | SMS content (max 459 characters) |

Send SMS request fields

#### Example Request

```bash
curl -4 -sS -i -X POST 'https://simcloud.co.za/api/sms.php' \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
    "recipient": "+27821234567",
    "message": "Hello World!"
}'
```

#### Success Response

```json
{
    "status": "success",
    "message": "SMS queued successfully",
    "sms_id": "123456",
    "sms_count": 1,
    "timestamp": "2024-10-24 14:30:00"
}
```

#### Error Response

```json
{
    "status": "error",
    "message": "Invalid recipient number, must be in the format +27XXXXXXXXX"
}
```

### 2. Check SMS Status

Query the status of a sent SMS message.

GET

#### Query Parameters

| Parameter | Type    | Required | Description           |
|-----------|---------|----------|-----------------------|
| sms_id    | integer | Yes      | ID of the SMS message |

Check SMS status query parameters

#### Example Request

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

#### Success Response

```json
{
    "sms_id": 123456,
    "status": "delivered"
}
```

## Important Notes

1.  Phone numbers must be in South African format (+27XXXXXXXXX)
2.  Messages are limited to 459 characters
3.  SMS credits are calculated based on message length:
    - 1-160 characters: 1 credit
    - 161-306 characters: 2 credits
    - 307-459 characters: 3 credits
4.  Status checks within 15 seconds of sending will return "queued" status
5.  The API supports UTF-8 encoded messages

## Statuses

- queued
- pending
- sent
- failed
- delivered
- staged
- unknown

`delivered` and `failed` are final. `sent` indicates supplier acceptance. Continue polling for the delivery receipt.

## Error Responses

SMS errors use `status: error` and `message`.

| HTTP Status | Description |
|----|----|
| 400 | Missing or invalid parameters, or wallet balance of R1 or less. |
| 401 | Unauthorized (invalid or missing token) |
| 404 | Not Found (SMS ID doesn't exist) |
| 500 | Could not confirm the queued message. If POST returns `code: confirmation_pending` and `sms_id`, poll that ID. For a `500` without an ID, check SMS history before resubmitting. |
| 503 | API temporarily unavailable. Honour `Retry-After` when present. |

SMS error responses

For technical support, please contact our support team at <customercare@freepaid.co.za>.
