# SMS API

The SMS API lets your app send a text to a South African mobile number and then check what happened to it. The send request queues the message and gives you an ID. Use that ID to tell when delivery succeeds or fails.

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

POST /api/sms.php · GET /api/sms.php

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

## Queue an SMS

Set recipient to a South African number in +27 format and send a UTF-8 message up to 459 characters. Message parts are counted at 160, 306 and 459 characters. HTTP 200 confirms queueing. Save sms_id and sms_count.

1. HTTP 400 covers invalid input or a wallet balance of R1 or less.
2. If HTTP 500 includes confirmation_pending and sms_id, poll that ID. If the outcome is unclear and you have no ID, check SMS History before trying again.

### POST /api/sms.php

```bash
curl -4 -sS -i -X POST "${SIMCLOUD_API_BASE:-https://simcloud.co.za}/api/sms.php" \
  -H "Authorization: Bearer $SIMCLOUD_API_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{
  "recipient": "YOUR_27_CELL",
  "message": "Example SMS from SIMcloud."
}'
```

HTTP 200 response excerpt

```json
{
  "status": "success",
  "sms_count": 1
}
```

> The POST queues a real SMS when you use your own account.

## Check SMS delivery

Set SIMCLOUD_SMS_ID to the original sms_id. Checks in the first 15 seconds return queued. A sent message is accepted by the supplier. Poll for delivered or failed before treating the delivery as final. HTTP 404 means no message matched for the account.

### GET /api/sms.php

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

HTTP 200 response excerpt

```json
{
  "status": "queued"
}
```

- [Check SMS History in the portal](https://simcloud.co.za/docs/guide/sms/#delivery)
