# SasuSync integration brief — cURL

> Hand this whole file to your coding agent. It contains everything needed to
> integrate SMS, one-time codes and voice calls, with no other page to read.

- **Base URL:** `https://sms.sasusync.com`
- **Auth:** every request sends the header `X-API-Key: <your key>`
- **Target language:** cURL
- **Human documentation:** https://sms.sasusync.com/docs/api
- **Get a key:** https://sms.sasusync.com/portal (shown once, at creation)

---

## Rules — follow these exactly

- Read the API key from an environment variable. Never write it into source, a mobile app, a browser bundle, or a repository.
- Build against `/smssandbox/v1/send` first. It is free, unlimited, and takes the identical body — switch that one URL to `/api/v1/send` to go live. It does NOT waive sender ID approval: an unapproved name returns 403 in sandbox exactly as it does live, so register the sender you intend to use before you start, not at go-live.
- `sender` must be a sender ID approved on this account. There is no shared or default sender name to fall back on — an unapproved name returns 403.
- Billing is per message part, not per message. Up to 160 GSM characters is one part; beyond that every 153 characters is another. Non-GSM characters (emoji, curly quotes, accents) cut a part to 70 characters. Read `balance.deducted` for the real figure.
- Retry only 429, 500, 502, 503, 504 and network timeouts, with exponential backoff. Never retry 400, 401, 402, 403, 409 or 422 — the same request will fail the same way.
- A timeout is not a failure. The message may already be on its way. Send every SMS with an `Idempotency-Key` header and retry with the same key - a repeat returns the first result instead of sending twice. Without one, check `/api/v1/status/{task_id}` before resending, or the recipient gets it twice and the account pays twice.
- For OTP, never store or compare the code. Call generate, then verify. One pending code per number; a second request while one is live returns 429.
- For webhooks, compute HMAC-SHA256 over the RAW request body bytes exactly as received. Parsing the JSON and re-serialising it changes the bytes and the signature will not match.
- Treat webhook events as at-least-once and possibly out of order. Key handling on `data.message_id` and make a repeat a no-op.
- Ghanaian numbers are accepted as `233552148347`, `+233552148347` or `0552148347`.
- A response carrying `queued: true` and a `task_id` is an acceptance, not an error. The message is held and delivered automatically, usually within a couple of minutes, and nothing is charged until it goes out. Never resend it — that delivers twice and bills twice.

---

## Billing model

The account holds **two separate balances**, spent in a fixed order.

| What is sent | Paid from | Notes |
| --- | --- | --- |
| SMS | SMS credits, then main balance | One credit per message part |
| OTP by SMS | SMS credits, then main balance | 3 credits per code (4 at 7-8 digits), see `rates.otp_sms_credits` |
| OTP by voice | Main balance | It is a phone call |
| Voice message | Main balance | Priced per recipient |

An OTP by SMS is paid in SMS credits, not the main balance — an empty main balance
does not stop it. This overflow is the same for a bulk SMS and for an OTP by SMS:
SMS credits are spent first, and any remainder is charged to the main balance at
the account's SMS rate, so nothing fails halfway or one code short. The main
balance on its own is needed only for voice.

---

## Reference client (cURL)

Copy this into the project and use it. It already implements the retry policy,
segment counting and webhook verification described above.

```bash
#!/usr/bin/env bash
# Minimal SasuSync helpers. Requires: curl, jq.
set -euo pipefail

BASE_URL="${SASUSYNC_BASE_URL:-https://sms.sasusync.com}"
: "${SASUSYNC_API_KEY:?set SASUSYNC_API_KEY}"

# Only 429 and 5xx are worth retrying; --retry-all-errors would also retry a
# 400, which will fail identically forever.
_call() {
  local method="$1" path="$2" body="${3:-}"
  local args=(-sS -X "$method" "${BASE_URL}${path}"
              -H "X-API-Key: ${SASUSYNC_API_KEY}"
              --max-time 30 --retry 3 --retry-delay 2 --retry-connrefused
              -w '\n%{http_code}')
  if [ -n "$body" ]; then
    args+=(-H "Content-Type: application/json" -d "$body")
  fi

  local out status payload
  out="$(curl "${args[@]}")"
  status="$(printf '%s' "$out" | tail -n1)"
  payload="$(printf '%s' "$out" | sed '$d')"

  if [ "$status" -ge 400 ]; then
    echo "SasuSync error $status: $(printf '%s' "$payload" | jq -r '.detail // .')" >&2
    return 1
  fi
  printf '%s' "$payload"
}

# send_sms <sender> <recipient> <message> [sandbox]
send_sms() {
  local path="/api/v1/send"
  [ "${4:-}" = "sandbox" ] && path="/smssandbox/v1/send"
  _call POST "$path" "$(jq -nc --arg s "$1" --arg r "$2" --arg m "$3" \
      '{sender:$s, recipients:[$r], message:$m}')"
}

# schedule_sms <sender> <recipient> <message> "YYYY-MM-DD HH:MM"
schedule_sms() {
  _call POST /schedule/v1/send "$(jq -nc --arg s "$1" --arg r "$2" --arg m "$3" --arg t "$4" \
      '{sender:$s, recipients:[$r], message:$m, schedule_time:$t}')"
}

message_status() { _call GET "/api/v1/status/$1"; }
balance()        { _call GET /api/v1/balance; }

# send_otp <number> <sender_id>
send_otp() {
  _call POST /otp/generate "$(jq -nc --arg n "$1" --arg s "$2" \
      '{number:$n, sender_id:$s, message:"Your code is %otp_code%. It expires in 5 minutes.",
        medium:"sms", length:6, expiry:5}')"
}

# verify_otp <number> <code>
verify_otp() {
  _call POST /otp/verify "$(jq -nc --arg n "$1" --arg c "$2" '{number:$n, code:$c}')"
}

# verify_webhook <raw_body_file> <signature>
# Hash the RAW bytes. Re-serialising parsed JSON changes them.
verify_webhook() {
  local expected
  expected="$(openssl dgst -sha256 -hmac "${SASUSYNC_WEBHOOK_SECRET}" -hex < "$1" | awk '{print $NF}')"
  [ "$expected" = "$2" ]
}
```

---

## Endpoints

### SMS

#### Send an SMS

`POST /api/v1/send`

One call sends to one number or to thousands.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `sender` | string | yes | A sender ID approved on this account, max 11 characters |
| `recipients` | string or array | yes | One number, or many in a single call |
| `message` | string | yes | Up to 650 characters |
| `metadata` | object | no | Your own key/value pairs, echoed back on webhooks |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/send" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": "YourBrand",
    "recipients": [
      "233552148347"
    ],
    "message": "Hello from SasuSync"
  }'
```

Response:

```json
{
  "success": true,
  "balance": {
    "deducted": 1,
    "remaining": 1649
  },
  "data": {
    "recipients_count": 1,
    "status": "queued",
    "task_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b",
    "job_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b"
  }
}
```

- `balance.deducted` is the number of message parts actually billed. Trust it over your own character count.
- Keep `data.task_id` - it is the id you check delivery with and the one webhooks refer to. `data.job_id` carries the same value, for older clients.
- If we can't reach the network at that moment, the send is still accepted and held: `"queued": true` with a `task_id`, sent automatically shortly after, and only charged when it goes out.
- A sender name not approved on the account returns 403.
- Send an `Idempotency-Key` header (any unique string of your own, up to 255 characters, e.g. `order-1042-confirmation`) to make retries safe: repeating the same request with the same key within 24 hours returns the first answer, with `idempotent_replay: true`, instead of sending and charging again. The same key with a different body is `422`; a retry while the first is still in progress is `409`. Works on `/api/v1/send`, `/schedule/v1/send` and the sandbox.
- You only pay for messages that arrive. If the network reports a message as not delivered (`failed`, `rejected`, `undelivered`, or expired by the network), its charge is refunded automatically, credits to credits and cash to cash. A bulk send is refunded for the recipients it didn't reach. Refunds show in your balance history.

#### Send a test SMS (free)

`POST /smssandbox/v1/send`

Identical request and response shape. Nothing is delivered and nothing is charged — but the sender must still be an approved sender ID.

```bash
curl -X POST "https://sms.sasusync.com/smssandbox/v1/send" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": "YourBrand",
    "recipients": [
      "233552148347"
    ],
    "message": "Hello from SasuSync"
  }'
```

Response:

```json
{
  "success": true,
  "balance": {
    "deducted": 1,
    "remaining": 1649
  },
  "data": {
    "recipients_count": 1,
    "status": "queued",
    "task_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b",
    "job_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b"
  }
}
```

- Build the entire integration against this path first, then change the single URL to go live.

#### Schedule an SMS

`POST /schedule/v1/send`

The same body as a normal send, plus `schedule_time`.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `schedule_time` | string | yes | `YYYY-MM-DD HH:MM`, 24-hour |

```bash
curl -X POST "https://sms.sasusync.com/schedule/v1/send" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": "YourBrand",
    "recipients": [
      "233552148347"
    ],
    "message": "Your appointment is tomorrow at 10am.",
    "schedule_time": "2026-08-09 13:08"
  }'
```

Response:

```json
{
  "success": true,
  "balance": {
    "deducted": 1,
    "remaining": 1649
  },
  "data": {
    "recipients_count": 1,
    "status": "queued",
    "task_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b",
    "job_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b"
  }
}
```

- The balance is checked when you schedule and again when it fires.

#### Check delivery status

`GET /api/v1/status/{task_id}`

Uses the `task_id` from the send response. You can only read your own messages.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/status/6f461b5a-7d35-4d55-97b0-00e420bf563b" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "status": "completed",
  "task_id": "6f461b5a-7d35-4d55-97b0-00e420bf563b",
  "delivery_status": "delivered",
  "message": "Found 1 message(s)",
  "summary": {
    "by_status": {
      "delivered": 1
    },
    "total": 1
  },
  "messages": [
    {
      "message_id": "e1cdeb12-093a-454d-adce-bc72e8ec175b",
      "recipient": "233248627968",
      "status": "delivered",
      "created_at": "2026-08-21T18:10:07.477061",
      "delivered_at": "2026-08-21T18:10:17.187007"
    }
  ]
}
```

- Prefer a webhook. Poll only as a fallback.
- Read `delivery_status`, not `status` - `status` is the task's own lifecycle (`completed`/`processing`), the same for a batch that landed perfectly and one where everybody bounced. `delivery_status` is always one of: `sent` (accepted by the network, not yet confirmed), `delivered`, `failed`, `partial` (a bulk send where some recipients got it and some didn't), `expired`, `pending` (still in flight with no single outcome yet), or `unknown` (no record found for that id).
- A batch of one recipient carries its detail in `messages[]`; a bulk send summarises it in `summary.by_status` instead - `delivery_status` already reads whichever shape applies, so it is the one field safe to parse either way.
- A sandbox message answers from its own record, instantly: `{"sandbox": true, "status": "delivered", "delivery_status": "delivered", "message": "..."}` - nothing is sent anywhere to check.
- A message that reached a final status more than a day ago answers from our own record in the same short form: `{"status": "delivered", "delivery_status": "delivered"}`.
- If the network is slow to answer, you get the last status we recorded with `"stale": true` instead of an error - ask again in a minute. Repeat polls within a minute return the same answer.

#### Check the balance

`GET /api/v1/balance`

Both `/api/v1/balance` and `/api/v1/check/balance` return this.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/balance" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "sms_credits": 1650,
  "main_balance": "25.00",
  "currency": "GHS",
  "sms_sendable": 2150,
  "otp_sendable": 825,
  "otp_voice_sendable": 113,
  "voice_sendable": 100,
  "rates": {
    "sms": "0.0500",
    "otp_sms_credits": 2,
    "otp_voice": "0.2200",
    "voice": "0.2500"
  },
  "pricing": {
    "currency": "GHS",
    "discount_percent": null,
    "negotiated": false,
    "published_rates": {
      "sms": "0.0500",
      "otp_sms": "0.0800",
      "otp_voice": "0.2200",
      "voice": "0.2500"
    },
    "your_rates": {
      "sms": "0.0500",
      "otp_sms": "0.0800",
      "otp_voice": "0.2200",
      "voice": "0.2500"
    },
    "partner": {
      "is_partner": false,
      "branding_tag": null
    }
  },
  "key_limits": {
    "sms": {
      "limit": 500,
      "used": 120,
      "remaining": 380,
      "low": false,
      "alert_threshold": null,
      "effective_alert_threshold": 50
    },
    "otp": {
      "limit": null,
      "used": 6,
      "remaining": null,
      "low": false,
      "alert_threshold": null,
      "effective_alert_threshold": null
    },
    "voice": {
      "limit": 0,
      "used": 0,
      "remaining": 0,
      "low": false,
      "alert_threshold": null,
      "effective_alert_threshold": 1
    }
  },
  "low_balance": {
    "credits_low": false,
    "cash_low": false,
    "empty": false,
    "credit_threshold": 50,
    "cash_threshold": "10.00"
  }
}
```

- `sms_sendable` is credits plus what the cash balance covers. Alert your own team before it reaches zero.
- `key_limits` is this key's own per-channel cap, set from the portal's API keys page (or `PATCH /portal/apps/{id}/limits`) - separate from the account balance above it. Useful when the same account's credit is spent from more than one system, each on its own key: `limit`/`remaining` come back `null` when that channel has no cap, not a very large number.
- Each channel's `low` is true once its own cap is nearly spent - ten percent or less left, or the `alert_threshold` set on the portal's Limits dialog for that channel if one was set - or once the account balance behind it is low (see `low_balance` below), whichever applies. A channel with no cap has none of its own to run low on (`alert_threshold` has no effect there either), so it reads straight off the account balance.
- `alert_threshold` is `null` unless the customer set their own value - it does not tell you the number actually being compared against on a capped channel that never had one set. `effective_alert_threshold` always gives that real number (the custom value if one was set, otherwise the automatic ten-percent default) on a capped channel, and `null` on one with no cap - that is the field to read if you just want to know when a channel is about to trip.
- `low_balance` is the same flag the portal dashboard warns with - poll it to show your own "balance is low" banner instead of only finding out from the low-balance email or `low_balance` webhook event sent to the account owner. `credit_threshold`/`cash_threshold` are the platform's default thresholds; `empty` means both balances are fully spent.

#### List SMS bundles

`GET /api/v1/bundles`

The bundles on sale, priced for your account - the same list as the portal's Top up page.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/bundles" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "currency": "GHS",
  "prices": {
    "sms": "0.0500",
    "otp_sms": "0.0800",
    "otp_voice": "0.2200",
    "voice": "0.2500"
  },
  "your_sms_rate": "0.0500",
  "negotiated": false,
  "discount_percent": null,
  "is_partner": false,
  "bundles": [
    {
      "id": 3,
      "price": "100.00",
      "sms_credits": 2300,
      "list_credits": 2300,
      "personalised": false,
      "effective_rate": "0.0435",
      "label": "Growth",
      "expires_days": null
    },
    {
      "id": 9,
      "price": "20.00",
      "sms_credits": 500,
      "list_credits": 500,
      "personalised": false,
      "effective_rate": "0.0400",
      "label": "Flash 30-day",
      "expires_days": 30
    }
  ]
}
```

- `sms_credits` is what this account actually gets. On a negotiated rate it can be more than `list_credits` (the published amount), and `personalised` says so.
- `expires_days` is `null` for credits that never expire, or the number of days a cheaper expiring bundle's credits last.

#### Quote a custom amount

`GET /api/v1/bundles/quote?amount={amount}`

What an amount of your choosing buys, before any money moves.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/bundles/quote?amount=50" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "currency": "GHS",
  "minimum": "5.00",
  "meets_minimum": true,
  "amount": "50.00",
  "sms_credits": 1110,
  "rate": "0.0450",
  "tier": "Starter",
  "non_expiring": {
    "amount": "50.00",
    "sms_credits": 1110,
    "rate": "0.0450",
    "tier": "Starter"
  },
  "expiring": {
    "amount": "50.00",
    "sms_credits": 1250,
    "rate": "0.0400",
    "tier": "Flash 30-day"
  }
}
```

- Two quotes, because the two kinds never mix: `non_expiring` and `expiring` (cheaper, but the credits lapse after 30 days). Pass `expiring` on the purchase to choose the second.
- `meets_minimum` is false below the smallest amount we sell (`minimum`).

#### Buy SMS credits

`POST /api/v1/bundles/purchase`

Start a purchase and get a payment link. Credits land on your account the moment the payment is confirmed.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `bundle_id` | integer | no | A bundle from `GET /api/v1/bundles`. Send this or `amount`. |
| `amount` | string | no | A custom amount in your currency instead of a bundle |
| `expiring` | boolean | no | With `amount` only: buy at the cheaper expiring rate. Default `false` |
| `redirect_url` | string | no | Where the payer is sent back to after paying |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/bundles/purchase" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "bundle_id": 3,
    "redirect_url": "https://yourapp.com/billing/done"
  }'
```

Response:

```json
{
  "success": true,
  "reference": "TOPUP-8f3a1c2b9d",
  "status": "pending",
  "amount": "100.00",
  "currency": "GHS",
  "sms_credits": 2300,
  "credits_expire_days": null,
  "payment_url": "https://checkout.example/pay/abc123",
  "created_at": "2026-11-04 09:12:03"
}
```

- Open `payment_url` for whoever is paying. They choose mobile money or card there and approve the prompt on their phone. We never ask for a PIN or an OTP, and neither should you.
- Nothing is credited until the payment is confirmed. Listen for the `topup_succeeded` webhook, or check `GET /api/v1/bundles/purchase/{reference}`.
- The price and credit count are fixed when the purchase starts, so a price change while someone is paying can't change what they get.
- An unpaid link expires after about 30 minutes. Calling this again starts a new, separate purchase - it doesn't reuse an open one.
- `429` if more than 10 purchases are started within 10 minutes on one account.

#### Check a purchase

`GET /api/v1/bundles/purchase/{reference}`

Whether it has been paid. Credits the account the moment it has.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/bundles/purchase/TOPUP-8f3a1c2b9d" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "reference": "TOPUP-8f3a1c2b9d",
  "status": "successful",
  "amount": "100.00",
  "currency": "GHS",
  "sms_credits": 2300,
  "credits_expire_days": null,
  "payment_url": "https://checkout.example/pay/abc123",
  "created_at": "2026-11-04 09:12:03",
  "credited": true,
  "sms_balance": 4950
}
```

- `status` is `pending`, `successful`, `failed` or `unknown` (the payment provider is still confirming - don't pay again). `sms_balance` is the account's SMS credits right now.
- Prefer the `topup_succeeded` webhook; poll this as a fallback, no more than once every few seconds.
- `404` for a reference that isn't one of this account's SMS purchases.

#### List purchases

`GET /api/v1/bundles/purchases`

This account's recent SMS credit purchases, newest first (`?limit=`, up to 100).

```bash
curl -X GET "https://sms.sasusync.com/api/v1/bundles/purchases" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "purchases": [
    {
      "reference": "TOPUP-8f3a1c2b9d",
      "status": "pending",
      "amount": "100.00",
      "currency": "GHS",
      "sms_credits": 2300,
      "credits_expire_days": null,
      "payment_url": "https://checkout.example/pay/abc123",
      "created_at": "2026-11-04 09:12:03"
    }
  ]
}
```

#### Save contacts

`POST /api/v1/contacts`

Save up to 5,000 contacts at once, optionally into a group.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `contacts` | array | yes | Each with `phone` and an optional `name` |
| `group` | string | no | Group to save them in (max 60 characters) |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/contacts" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "group": "Customers",
    "contacts": [
      {
        "phone": "0241234567",
        "name": "Ama Mensah"
      },
      {
        "phone": "0551234567",
        "name": "Kofi Boateng"
      }
    ]
  }'
```

Response:

```json
{
  "success": true,
  "message": "Import complete",
  "added": 2,
  "duplicates": 0,
  "skipped": [],
  "skipped_count": 0
}
```

- A number already saved in that group is counted in `duplicates`, not saved twice. The same number can be in several groups.
- Numbers that aren't valid are listed in `skipped` and nothing else fails.

#### List contacts

`GET /api/v1/contacts?group=Customers`

Your saved contacts, filtered by `group` and/or `search` (name or number), paged with `limit` (up to 500) and `offset`.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/contacts?group=Customers" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "total": 2,
  "limit": 100,
  "offset": 0,
  "contacts": [
    {
      "id": 311,
      "phone": "233241234567",
      "name": "Ama Mensah",
      "group": "Customers"
    },
    {
      "id": 312,
      "phone": "233551234567",
      "name": "Kofi Boateng",
      "group": "Customers"
    }
  ]
}
```

- `group=Uncategorised` lists contacts saved with no group.

#### List groups

`GET /api/v1/contacts/groups`

Every contact group with how many contacts it holds.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/contacts/groups" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "groups": [
    {
      "name": "Customers",
      "count": 2
    },
    {
      "name": "Uncategorised",
      "count": 14
    }
  ]
}
```

#### Edit a contact

`PATCH /api/v1/contacts/{id}`

Change a contact's `phone`, `name` or group (`category`). Fields you leave out keep their value; an empty `category` removes it from its group.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `phone` | string | no | New number |
| `name` | string | no | New name |
| `category` | string | no | New group |

```bash
curl -X PATCH "https://sms.sasusync.com/api/v1/contacts/311" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ama K. Mensah",
    "category": "VIP"
  }'
```

- `409` if that number is already saved in that group.

#### Rename a group

`POST /api/v1/contacts/groups/rename`

Renaming onto a group that already exists merges the two, keeping each number once.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `group` | string | yes | Current name |
| `new_name` | string | yes | New name |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/contacts/groups/rename" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "group": "Customers",
    "new_name": "Clients"
  }'
```

- Also `POST /api/v1/contacts/groups/delete` with `group` (and `delete_contacts: true` to delete its contacts too, otherwise they are kept with no group), `POST /api/v1/contacts/bulk` with `ids` and `action` (`delete`, `move` or `copy`, plus `group`), and `DELETE /api/v1/contacts/{id}`.

#### Send to a group

`POST /api/v1/campaigns`

One message to every contact in a saved group, and/or a list of numbers, sent in the background. Returns at once with a `campaign_id`.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `sender` | string | yes | An approved sender ID |
| `message` | string | yes | Up to 650 characters |
| `group` | string | no | A saved contact group. Send this, `recipients`, or both |
| `recipients` | array | no | Extra numbers |
| `exclude` | array | no | Numbers to leave out, e.g. a few people in the group who shouldn't get this one |
| `schedule_time` | string | no | Send later instead of now (ISO 8601) |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/campaigns" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": "YourBrand",
    "message": "Our Easter sale starts today!",
    "group": "Customers"
  }'
```

Response:

```json
{
  "success": true,
  "campaign_id": 88,
  "job_id": 88,
  "queued": 2,
  "duplicates_removed": 0,
  "excluded": 0,
  "invalid": [],
  "segments": 1,
  "total_sms": 2,
  "scheduled_at": null,
  "status": "queued"
}
```

- A number in the group and in `recipients` gets one message, not two.
- `exclude` takes numbers in any format (`0241234567` or `233241234567`); the response's `excluded` says how many were left out.
- Takes an `Idempotency-Key` header like `/api/v1/send`, so a retried call never starts the same campaign twice.
- Poll `GET /api/v1/campaigns/{id}` for `sent`, `failed` and `percent`, or list recent ones with `GET /api/v1/campaigns`.
- `POST /api/v1/campaigns/{id}/cancel` cancels one that hasn't started, or stops one part-way; nobody not reached is charged.
- `GET /api/v1/campaigns/{id}/recipients?result=failed` lists the numbers that failed (or `sent`, `not sent`).

#### Campaign progress

`GET /api/v1/campaigns/{id}`

How far a campaign has got.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/campaigns/88" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "id": 88,
  "status": "running",
  "sender": "YourBrand",
  "total": 2,
  "sent": 1,
  "failed": 0,
  "percent": 50,
  "segments": 1,
  "error": null,
  "scheduled_at": null,
  "created_at": "2026-11-04T10:00:00",
  "finished_at": null
}
```

### OTP

#### Generate a one-time code

`POST /otp/generate`

We generate the code, deliver it, and remember it. Never store or compare codes yourself.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `number` | string | yes | The recipient |
| `sender_id` | string | yes | An approved sender ID |
| `message` | string | yes | Must contain `%otp_code%`, max 160 characters |
| `medium` | string | no | `sms` (default) or `voice` |
| `otp_type` | string | no | `numeric` (default) or `alphanumeric` |
| `expiry` | integer | no | 1 to 60 minutes, default 5 |
| `length` | integer | no | 4 to 8 characters, default 6 |

```bash
curl -X POST "https://sms.sasusync.com/otp/generate" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "number": "233552148347",
    "sender_id": "YourApp",
    "message": "Your code is %otp_code%. It expires in 5 minutes.",
    "medium": "sms",
    "otp_type": "numeric",
    "expiry": 5,
    "length": 6
  }'
```

Response:

```json
{
  "success": true,
  "otp_id": 4417,
  "message": "OTP sent"
}
```

- `%otp_code%` is mandatory in the message and is replaced with the generated code.
- One pending code per number. Asking for a second while one is live returns 429.
- The code is never in the response. It goes to the handset only.

#### Verify a one-time code

`POST /otp/verify`

Three attempts, then the code is dead. Verification is free.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `number` | string | one of | The number the code went to. Omit if you send `otp_id`. |
| `otp_id` | integer | one of | The id `/otp/generate` returned, so you need not keep the number. An id your application did not send is refused. |
| `code` | string | yes | What the user typed |

```bash
curl -X POST "https://sms.sasusync.com/otp/verify" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "number": "233552148347",
    "code": "123456"
  }'
```

Response:

```json
{
  "success": true,
  "message": "OTP verified",
  "verified": true,
  "reason": "verified"
}
```

- **Branch on `verified`, not on the status code.** A wrong code is a **200** with `verified: false` and a `reason` — it is an answer, not an error. A non-2xx means the call itself failed and says nothing about whether the code was right.
- `reason` tells you which 'no' it was: `wrong_code` for a mistyped code, `expired` once it has timed out, `no_pending_code` when nothing was ever sent to that number, and `already_verified` when the code was right but has already been spent — usually a double submit, and worth treating as done rather than as a failure. A wrong code also carries `attempts_remaining` where the provider reports it; three wrong tries kill the code.

#### How many codes can still be sent

`GET /otp/balance`

Derived from SMS credits, because an OTP over SMS is billed in them.

```bash
curl -X GET "https://sms.sasusync.com/otp/balance" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "otp_sendable": 825,
  "otp_voice_sendable": 113,
  "sms_credits": 1650,
  "main_balance": "25.00",
  "currency": "GHS",
  "credits_per_otp": 2,
  "voice_otp_cost": "0.2200"
}
```

### Voice

#### Send a voice message

`POST /voice/v1/send`

Send `text` to be read aloud, or upload `voice_file` as multipart.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `recipients` | string or array | yes | One number or many |
| `text` | string | no | The words to read aloud |
| `voice_file` | file | no | An audio file, sent multipart instead of JSON |

```bash
curl -X POST "https://sms.sasusync.com/voice/v1/send" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "recipients": [
      "233552148347"
    ],
    "text": "Your delivery arrives today between 2 and 4 PM."
  }'
```

Response:

```json
{
  "success": true,
  "balance": {
    "deducted": "0.2500",
    "remaining": "24.75"
  },
  "data": {
    "recipients_count": 1,
    "status": "queued",
    "task_id": "b1f4c9d2-3a77-4e10-9c22-7f0e5a1b8d43"
  }
}
```

- Send either `text` or `voice_file`, not both.
- Voice is billed to the main balance, not to SMS credits. A brand-new account has credits but no cash, so the first voice call returns 402 until the main balance is topped up.

### Sender IDs

#### Register a sender ID

`POST /sender/id/register`

Queues the name for review. Nothing reaches the networks until it is approved.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `sender_name` | string | yes | Max 11 characters |
| `purpose` | string | yes | What it will be used for. A vague purpose is the usual cause of a slow review. |

```bash
curl -X POST "https://sms.sasusync.com/sender/id/register" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_name": "YourBrand",
    "purpose": "Order confirmations for our customers"
  }'
```

Response:

```json
{
  "success": true,
  "sender_name": "YourBrand",
  "status": "pending",
  "review_status": "pending_review",
  "message": "Request submitted. Sender IDs are reviewed before registration; poll /sender/id/status for the outcome."
}
```

- A name already registered on the platform returns 409.
- A name that cannot be approved returns 400 with the reason: a bare generic word (Verify, Alert, Info), another organisation's brand, only digits, under 3 characters, or symbols other than space . - &.
- If the networks later block an approved name, sends under it return 403 and nothing is sent or charged; its status reads blocked.
- Verification is instant; approval usually completes in 10 to 30 minutes. Use the sandbox meanwhile.

#### Check a sender ID's status

`GET /sender/id/status?sender_name={name}`

Returns `pending`, `approved`, `rejected` or `not_found`.

```bash
curl -X GET "https://sms.sasusync.com/sender/id/status?sender_name=YourBrand" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

- Only `approved` can be used on a live send.

### Virtual Numbers

#### Browse services

`GET /api/v1/virtual/services`

Every service on sale, most popular first (WhatsApp, Facebook, Telegram...), each with its logo - the starting point for a service picker.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/virtual/services" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "total": 2,
  "services": [
    {
      "service": "wa",
      "service_name": "WhatsApp",
      "country_count": 61,
      "icon": "https://sms.sasusync.com/vn-icon/71654.webp"
    },
    {
      "service": "tg",
      "service_name": "Telegram",
      "country_count": 58,
      "icon": "https://sms.sasusync.com/vn-icon/71562.webp"
    }
  ]
}
```

- `search` and `limit`/`offset` (default 40, max 100) narrow and page it.
- `icon` is a full URL to the service's logo (WebP, 92x92), served from our domain and safe to show in your own app. It is `null` for the few services without one, so draw a placeholder then.

#### Check prices

`GET /api/v1/virtual/prices`

Every country priced for a service, in your account's currency, read live off the same catalog the admin console edits - a price changed there is reflected on your very next call.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/virtual/prices?service=wa" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "currency": "GHS",
  "total": 1,
  "prices": [
    {
      "service": "wa",
      "country": "38",
      "price": "25.80",
      "service_name": "WhatsApp",
      "country_name": "Ghana",
      "available": 20952,
      "in_stock": true,
      "flag": "https://sms.sasusync.com/vn-icon/72745.webp"
    }
  ]
}
```

- `price` is a string with at least two decimal places (`25.80`) - parse it as a number.
- `flag` is a full URL to the country's flag (WebP, round), or `null` when there is none. `available` is how many numbers the supplier had at the last hourly check; `in_stock` false means buying it will fail right now - sold-out countries come last.
- `sort` is `name`, `price_asc`, `price_desc` or `stock` (most available first).
- Without `service`, this is a general search across the whole catalog instead - still capped and paged (`limit`, default 50, max 100; `offset`).
- Nothing here stops you pricing your own resale above what's returned - this is exactly what you pay, to build your own markup on top of.

#### Check the Virtual Numbers balance

`GET /api/v1/virtual/balance`

A separate wallet from SMS/OTP/voice credit, topped up on its own in the portal.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/virtual/balance" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "currency": "GHS",
  "balance": "48.00"
}
```

- Read this before `/buy` - a number costing more than the balance holds is refused with `402` before anything is bought upstream.
- `balance` has no fixed number of decimal places either - see `/prices`.

#### Buy a number

`POST /api/v1/virtual/buy`

Reserves a real, working number for one service and charges the price from `/prices` at the moment of purchase.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `service` | string | yes | A service code from `/services` |
| `country` | string | no | A country code from `/prices` - defaults to `any`, letting the system pick whichever available country is cheapest |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/virtual/buy" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "service": "wa",
    "country": "any"
  }'
```

Response:

```json
{
  "order": {
    "id": 4821,
    "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
    "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
    "phone_number": "+233201142183",
    "service": "wa",
    "service_name": "WhatsApp",
    "country": "38",
    "country_name": "Ghana",
    "price": "25.80",
    "status": "waiting",
    "otp_code": null,
    "created_at": "2026-08-21T14:02:10",
    "completed_at": null,
    "timeout_seconds": 1200,
    "cancel_lock_seconds": 300,
    "can_retry": true
  },
  "balance": "22.20"
}
```

- `402` if the balance does not cover the price - nothing is bought upstream when that happens.
- `409` if that number cannot be supplied at the listed price right now. Nothing is charged; try another country or try again later.
- The order starts `waiting`. Poll `/orders/{id}` (or build a flow around `cancel_lock_seconds`/`timeout_seconds` from its response) until a code arrives or you give up on it.

#### List your orders

`GET /api/v1/virtual/orders`

Every number you've bought through this key's account, newest first.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/virtual/orders" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "orders": [
    {
      "id": 4821,
      "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
      "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
      "phone_number": "+233201142183",
      "service": "wa",
      "service_name": "WhatsApp",
      "country": "38",
      "country_name": "Ghana",
      "price": "25.80",
      "status": "received",
      "otp_code": "482910",
      "created_at": "2026-08-21T14:02:10",
      "completed_at": null,
      "timeout_seconds": null,
      "cancel_lock_seconds": null,
      "can_retry": true
    }
  ]
}
```

- `limit` defaults to 25.

#### Check an order's status

`GET /api/v1/virtual/orders/{order_id}`

Checks live with the upstream provider while the order is still `waiting`, so this alone is enough to build on with no webhook.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/virtual/orders/4821" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "id": 4821,
  "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
  "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
  "phone_number": "+233201142183",
  "service": "wa",
  "service_name": "WhatsApp",
  "country": "38",
  "country_name": "Ghana",
  "price": "25.80",
  "status": "received",
  "otp_code": "482910",
  "created_at": "2026-08-21T14:02:10",
  "completed_at": null,
  "timeout_seconds": null,
  "cancel_lock_seconds": null,
  "can_retry": true
}
```

- `status` moves `waiting` -> `received` (code arrived, in `otp_code`), `cancelled` (refunded) or `expired` (also refunded, after `timeout_seconds`).
- An order belonging to another account on your key's own credentials reads back `404`, same as any other id scoped to your account.

#### Cancel an order

`POST /api/v1/virtual/orders/{order_id}/cancel`

Gives back a number you no longer want and refunds its price.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/virtual/orders/4821/cancel" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "order": {
    "id": 4821,
    "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
    "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
    "phone_number": "+233201142183",
    "service": "wa",
    "service_name": "WhatsApp",
    "country": "38",
    "country_name": "Ghana",
    "price": "25.80",
    "status": "cancelled",
    "otp_code": null,
    "created_at": "2026-08-21T14:02:10",
    "completed_at": "2026-08-21T14:03:40",
    "timeout_seconds": null,
    "cancel_lock_seconds": null,
    "can_retry": false
  },
  "balance": "48"
}
```

- `409` if the order already reached a final state, or if the provider refuses an early cancel - `cancel_lock_seconds` on the order is that window.
- Refunding is idempotent on our side either way: a cancel that lands, and a background check that later discovers the same cancellation upstream, never refund twice.

#### Mark an order finished

`POST /api/v1/virtual/orders/{order_id}/finish`

Tells the provider you're done with a number that already received its code - closes it out cleanly instead of leaving it to time out.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/virtual/orders/4821/finish" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "order": {
    "id": 4821,
    "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
    "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
    "phone_number": "+233201142183",
    "service": "wa",
    "service_name": "WhatsApp",
    "country": "38",
    "country_name": "Ghana",
    "price": "25.80",
    "status": "finished",
    "otp_code": "482910",
    "created_at": "2026-08-21T14:02:10",
    "completed_at": "2026-08-21T14:04:02",
    "timeout_seconds": null,
    "cancel_lock_seconds": null,
    "can_retry": false
  }
}
```

- `409` if the order hasn't received a code yet - only a `received` order can be finished.

#### Request another code on the same number

`POST /api/v1/virtual/orders/{order_id}/retry`

The first code never arrived, or arrived wrong - ask the same number for another one rather than buying a new one.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/virtual/orders/4821/retry" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "order": {
    "id": 4821,
    "service_icon": "https://sms.sasusync.com/vn-icon/71654.webp",
    "country_icon": "https://sms.sasusync.com/vn-icon/72745.webp",
    "phone_number": "+233201142183",
    "service": "wa",
    "service_name": "WhatsApp",
    "country": "38",
    "country_name": "Ghana",
    "price": "25.80",
    "status": "waiting",
    "otp_code": null,
    "created_at": "2026-08-21T14:02:10",
    "completed_at": null,
    "timeout_seconds": 1200,
    "cancel_lock_seconds": 300,
    "can_retry": true
  }
}
```

- Free - GrizzlySMS doesn't charge for this either, confirmed directly against their docs.
- `409` if this specific number doesn't support a second code at all - `can_retry` on the order tells you that upfront, before you call this.

### Email

#### List your domains

`GET /api/v1/email/domains`

Every domain you've added, with its current onboarding status.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/domains" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "domains": [
    {
      "domain": "mail.yourbrand.com",
      "mode": "hosting",
      "status": "verified",
      "dns_records": [
        {
          "type": "MX",
          "host": "@",
          "value": "mail.sasusync.com",
          "priority": 10
        },
        {
          "type": "TXT",
          "host": "@",
          "value": "v=spf1 ip4:169.58.169.30 -all"
        },
        {
          "type": "TXT",
          "host": "sasusync._domainkey",
          "value": "v=DKIM1; k=rsa; p=\u2026"
        },
        {
          "type": "TXT",
          "host": "_dmarc",
          "value": "v=DMARC1; p=quarantine; \u2026"
        }
      ],
      "detected_provider": null,
      "verified_at": "2026-10-18T10:21:00",
      "created_at": "2026-10-18T10:04:12"
    }
  ]
}
```

#### Add a domain

`POST /api/v1/email/domains`

Starts onboarding a domain you own. Returns a one-time TXT record to publish, proving you control it - this is the only step that moves before ownership is shown.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `domain` | string | yes | The domain to onboard, e.g. `mail.yourbrand.com` |
| `mode` | string | yes | `hosting` - real mailboxes + webmail live here (full MX/SPF/DKIM/DMARC). `sending` - keep your existing inbox exactly as it is; only DKIM is touched, your MX is never changed. |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "mail.yourbrand.com",
    "mode": "hosting"
  }'
```

Response:

```json
{
  "domain": "mail.yourbrand.com",
  "mode": "hosting",
  "status": "pending_claim",
  "dns_records": {
    "challenge": {
      "type": "TXT",
      "host": "_mailverify.mail.yourbrand.com",
      "value": "sc-verify=ab12c3d4e5f6\u2026"
    }
  },
  "detected_provider": null,
  "verified_at": null,
  "created_at": "2026-10-18T10:04:12"
}
```

- `409` if this domain is already on your account.

#### Check a domain

`GET /api/v1/email/domains/{domain}`

Its current status and whichever DNS records are relevant right now.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "domain": "mail.yourbrand.com",
  "mode": "hosting",
  "status": "claimed",
  "dns_records": [
    {
      "type": "MX",
      "host": "@",
      "value": "mail.sasusync.com",
      "priority": 10
    },
    {
      "type": "TXT",
      "host": "@",
      "value": "v=spf1 ip4:169.58.169.30 -all"
    },
    {
      "type": "TXT",
      "host": "sasusync._domainkey",
      "value": "v=DKIM1; k=rsa; p=\u2026"
    },
    {
      "type": "TXT",
      "host": "_dmarc",
      "value": "v=DMARC1; p=quarantine; \u2026"
    }
  ],
  "detected_provider": null,
  "verified_at": null,
  "created_at": "2026-10-18T10:04:12"
}
```

- `status` walks forward: `pending_claim` (publish the one-time TXT, then call `/verify`) -> `claimed` (ownership proven - publish the records now shown, then call `/verify` again) -> `verified`. A failed final check reads `failed`, not an error - the same records are still correct, just not matching live DNS yet; call `/verify` again once they've propagated.

#### Verify a domain

`POST /api/v1/email/domains/{domain}/verify`

The same action does two different things depending on where the domain currently is - call it again each time you've published something new.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/verify" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "domain": "mail.yourbrand.com",
  "mode": "hosting",
  "status": "verified",
  "dns_records": [
    {
      "type": "MX",
      "host": "@",
      "value": "mail.sasusync.com",
      "priority": 10
    },
    {
      "type": "TXT",
      "host": "@",
      "value": "v=spf1 ip4:169.58.169.30 -all"
    },
    {
      "type": "TXT",
      "host": "sasusync._domainkey",
      "value": "v=DKIM1; k=rsa; p=\u2026"
    },
    {
      "type": "TXT",
      "host": "_dmarc",
      "value": "v=DMARC1; p=quarantine; \u2026"
    }
  ],
  "detected_provider": null,
  "verified_at": "2026-10-18T10:21:00",
  "created_at": "2026-10-18T10:04:12"
}
```

- While `pending_claim`: checks the one-time ownership TXT. Not found yet is not an error - you get the domain back still `pending_claim`, try again once DNS has propagated. Found -> the domain becomes `claimed` and the response now carries the real MX/SPF/DKIM/DMARC (or DKIM-only) records to publish.
- While `claimed` or `failed`: does the final live DNS check instead, against those records. Passes -> `verified`.

#### Connect Cloudflare (one click, every record)

`POST /api/v1/email/domains/{domain}/cloudflare`

Get a Cloudflare sign-in link for the domain owner. Once they allow access, we add every record ourselves (the ownership TXT too, so this works right after adding the domain), then verify the domain.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/cloudflare" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "authorize_url": "https://mcp.cloudflare.com/authorize?response_type=code&client_id=\u2026",
  "expires_in": 900
}
```

- Open `authorize_url` for the person who manages the domain's DNS in Cloudflare. The link works once and lasts 15 minutes.
- We ask Cloudflare only to read zones and edit DNS. The sign-in is used for this one setup and never stored.
- Existing records are respected: an SPF record is merged with ours, an existing DMARC policy is kept. On full-hosting domains our MX replaces the old one (mail moves to us).
- Follow progress with the status endpoint below. `409` if the domain is already verified or a setup is already running.

#### Connect Cloudflare status

`GET /api/v1/email/domains/{domain}/cloudflare`

`starting` -> `adding_ownership` -> `waiting_ownership` -> `adding_records` -> `waiting_records` -> `done`, or `error` with a message. `null` before any setup.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/cloudflare" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "state": "done",
  "message": "mail.yourbrand.com is verified.",
  "steps": [
    {
      "type": "TXT",
      "name": "_mailverify.mail.yourbrand.com",
      "action": "added"
    },
    {
      "type": "TXT",
      "name": "sasusync._domainkey.mail.yourbrand.com",
      "action": "added"
    }
  ],
  "domain": {
    "domain": "mail.yourbrand.com",
    "status": "verified"
  }
}
```

- `steps` lists each record and what happened to it: added, updated, merged, already there, or kept yours.

#### Set up DNS for me (DNS Connect)

`POST /api/v1/email/domains/{domain}/dns-connect`

Get a one-time link that sets the domain's mail records up for you: on Cloudflare the domain owner signs in once and every record is added; on any other provider the page lists the exact records to paste.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/dns-connect" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "session_id": "dcs_8f2a\u2026",
  "status": "created",
  "connect_url": "https://mail.sasusync.com:4100/dns/connect?session=dcs_8f2a\u2026",
  "records": [
    {
      "type": "MX",
      "host": "@",
      "value": "mail.sasusync.com",
      "priority": 10
    }
  ],
  "reused": false
}
```

- Open `connect_url` in a new tab or window for the person who controls the domain's DNS. It lasts 24 hours and works for this one domain only. Calling this again within that time returns the same link (`reused: true`).
- When they finish, they're sent back to your Email page. Or poll the status endpoint below.
- The domain must be in Cloudflare for the automatic path; otherwise the page shows the records to paste.
- `409` if the domain is already verified, or still `pending_claim`: ownership has to be proven first (publish the one-time TXT from the add-domain response and call verify). DNS Connect then adds every other record.

#### DNS Connect status

`GET /api/v1/email/domains/{domain}/dns-connect`

Where DNS setup stands: `created` -> `connecting` -> `pushed` -> `verified`, or `manual` (records to paste) or `error`. Add `verify=1` to re-check DNS now.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `verify` | boolean | no | `1` to re-check DNS right now |

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/dns-connect?verify=1" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "status": "verified",
  "provider": "cloudflare",
  "checks": {
    "mx": {},
    "spf": {},
    "dkim": {},
    "dmarc": {}
  },
  "push": [
    {
      "ok": true,
      "type": "MX",
      "name": "mail.yourbrand.com"
    }
  ],
  "error": null,
  "domain": {
    "domain": "mail.yourbrand.com",
    "status": "verified"
  }
}
```

- Once the records are live, the domain itself is verified here too - no separate verify call needed.
- `404` if DNS setup was never started for the domain.

#### Remove a domain

`DELETE /api/v1/email/domains/{domain}`

Removes it from your account. DNS records and any mailboxes on it are not removed automatically - undo those yourself if you no longer need them.

```bash
curl -X DELETE "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "message": "Domain removed. DNS records and anything upstream are not removed automatically."
}
```

#### Send an email

`POST /api/v1/email/send`

One message, from a domain you've verified.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `from` | string | yes | Must be `@` a domain you've verified on this account |
| `to` | string | yes | A single recipient address |
| `subject` | string | yes |  |
| `html` | string | no | At least one of `html`/`text` is required |
| `text` | string | no | At least one of `html`/`text` is required |
| `headers` | object | no | Raw header passthrough, e.g. for Gmail's bulk-sender one-click rule - at most 10 entries, no line breaks in a key or value |
| `list_unsubscribe` | object | no | `{"url": "https://...", "mailto": "..."}` - the friendlier alternative to building the header yourself; a `url` gets `List-Unsubscribe-Post: List-Unsubscribe=One-Click` added automatically |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/send" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "hello@mail.yourbrand.com",
    "to": "customer@example.com",
    "subject": "Welcome aboard",
    "html": "<p>Thanks for joining.</p>"
  }'
```

Response:

```json
{
  "id": "a1b2c3d4-\u2026",
  "status": "queued",
  "idempotent_replay": false,
  "queued_for_retry": false
}
```

- `409` if `from`'s domain isn't a verified domain on this account.
- A brand-new domain has no sending history anywhere - its first messages can land in spam while mail providers build trust in it. Warm up gradually rather than sending a large volume on day one.
- Delivery is asynchronous: a `200` means the message was accepted onto the send queue, not that it was delivered. `status` starts at `queued`; check `GET /api/v1/email/sends` for the real outcome (`delivered`, `bounced`, `failed`, or `suppressed` - skipped because that address previously bounced or complained, to protect your sending reputation).
- Optional `Idempotency-Key` header (any string unique to this message, e.g. an order id) makes a retried call return the original result instead of sending twice - the response's own `idempotent_replay` field says when that happened. Scoped to your account; only detected as a replay while the key is still cached, so retry promptly.
- For Gmail's one-click unsubscribe rule: send `list_unsubscribe` with an `https` `url` (a `mailto` fallback is recommended too) - that endpoint must accept an HTTP POST with no cookies and suppress the recipient within ~48h. Whatever headers the message actually carries, including these, are DKIM-signed.
- On the rare network timeout to our own upstream, `queued_for_retry` is `true` and `id` is `null` - nothing failed, the send is held and retried automatically under the same idempotency key, safe from a double send either way. Check `GET /api/v1/email/sends` once retried for the real `id` and status.

#### List what you've sent

`GET /api/v1/email/sends`

The last 100 messages on your account, newest first.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/sends" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "sends": [
    {
      "id": "a1b2c3d4-\u2026",
      "from": "hello@mail.yourbrand.com",
      "to": "customer@example.com",
      "subject": "Welcome aboard",
      "status": "delivered",
      "created_at": "2026-10-18T10:32:00"
    },
    {
      "id": "e5f6g7h8-\u2026",
      "from": "hello@mail.yourbrand.com",
      "to": "customer@example.com",
      "subject": "Welcome aboard",
      "status": "suppressed",
      "created_at": "2026-10-18T10:31:00"
    }
  ]
}
```

- No local log of your own to keep - `status` is kept current as delivery actually happens.

#### List your mailboxes

`GET /api/v1/email/mailboxes`

Every mailbox created on your verified `hosting`-mode domains.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/mailboxes" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "mailboxes": [
    {
      "email": "hello@mail.yourbrand.com",
      "domain": "mail.yourbrand.com",
      "display_name": "Hello Desk",
      "webmail_enabled": true,
      "is_agent": false,
      "created_at": "2026-10-18T10:30:00"
    }
  ]
}
```

- Never carries a password - that's only ever in the one-time response from creating the mailbox, below.

#### Create a mailbox

`POST /api/v1/email/mailboxes`

A real IMAP/SMTP + webmail inbox on a verified `hosting`-mode domain.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `domain` | string | yes | Must be a verified domain on this account, added with mode `hosting` |
| `user` | string | yes | The local part, e.g. `hello` for `hello@mail.yourbrand.com` |
| `display_name` | string | no |  |
| `notify_email` | string | no | If given, we email sign-in details for a mail app (Gmail, Outlook, …) to this address ourselves - our own message, nothing from the underlying mail platform. Leave it out and just read `password`/`imap`/`smtp` off this response instead. |
| `agent` | boolean | no | `true` makes this an **agent mailbox**: an address an AI agent drives with one scoped token (`agent_token`, returned once) instead of a person's password. No webmail invite or welcome email is created unless you also set `webmail`. See "Agent mailboxes" below. |
| `webmail` | boolean | no | Agent mailboxes only. `true` also gives a person a browser inbox over the same mailbox, to watch or take over from the agent. Leave it out and nothing human-facing is created. |
| `webhook_url` | string | no | Agent mailboxes only. An `https://` URL we POST each inbound message to as JSON (retried with backoff, then dead-lettered). Private/loopback hosts are refused. |
| `webhook_include_body` | boolean | no | Agent mailboxes only. `true` adds the full `raw_email` to each webhook, so the agent needs no second fetch. Default `false`. |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "mail.yourbrand.com",
    "user": "hello",
    "display_name": "Hello Desk"
  }'
```

Response:

```json
{
  "email": "hello@mail.yourbrand.com",
  "password": "kx7m-2pq9-rbaz",
  "must_change_password": true,
  "webmail": {
    "enabled": true,
    "pending": false,
    "url": "https://webmail.sasusync.com"
  },
  "imap": {
    "host": "mail.sasusync.com",
    "port": 993,
    "security": "SSL/TLS"
  },
  "smtp": {
    "host": "mail.sasusync.com",
    "port": 587,
    "security": "STARTTLS"
  },
  "welcome": {
    "mode": "manual",
    "sent": false
  }
}
```

- Creating an **agent mailbox** (`"agent": true`) returns `agent_token` instead of relying on `password`: shown once, store it immediately. The response also carries `agent_connect` - the MCP URL, a paste-ready MCP client config, the auth header and the API base - so there is nothing else to look up. Agent mailboxes count against your plan's mailbox limit like any other.
- `password` is shown exactly once, right here - store it immediately, it cannot be retrieved again. It's a webmail password (must be changed on first webmail sign-in) - for a stable one that works in a mail app with no forced change, use `notify_email` above, or the dedicated endpoint below any time afterwards.
- `409` if the domain isn't verified yet, or isn't `hosting` mode (a `sending`-mode domain keeps its mailbox wherever it already is - there's nothing to create here).
- `webmail.enabled` can read `false` right after creation (`pending`) - the mailbox itself still works over IMAP/SMTP immediately either way.

#### Send mail-app login details

`POST /api/v1/email/mailboxes/{domain}/{user}/login-details`

Mints a fresh, stable app password for an existing mailbox and emails it - our own message, never a word of the underlying mail platform. Works any time after the mailbox exists, not just at creation. A mailbox has one mail-app password at a time, so a new one replaces the previous one.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `to` | string | yes | Where to send it |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/login-details" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "someone@example.com"
  }'
```

Response:

```json
{
  "message": "Sign-in details sent to someone@example.com."
}
```

- `404` if there's no such mailbox on this account.

#### Mail-app login status

`GET /api/v1/email/mailboxes/{domain}/{user}/app-login`

Whether the mailbox has a mail-app (IMAP/SMTP) password, with its label and the date it was issued. Never the password itself.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/app-login" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "set": true,
  "label": "iPhone Mail",
  "issued_at": "2026-11-12T10:00:00Z"
}
```

- A mailbox has one mail-app password at a time. Issuing a new one (login details, above) replaces the old one.

#### Revoke the mail-app login

`DELETE /api/v1/email/mailboxes/{domain}/{user}/app-login`

Every phone or desktop mail app signed in with it stops working at once. Webmail sign-in is not affected.

```bash
curl -X DELETE "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/app-login" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "message": "Mail-app password revoked."
}
```

#### Set mailbox rules

`PUT /api/v1/email/mailboxes/{domain}/{user}/rules`

Rules run on our mail servers as each message arrives, so every device sees the same result. Replaces the whole list; send an empty list to clear them.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `rules` | array | yes | Up to 50. Each: `header` (`from`, `to`, `cc`, `subject`, `newsletter`), `contains` (not needed for `newsletter`), `action` (`star`, `markread`, `fileinto`, `junk`, `discard`), and `folder` for `fileinto`. |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/rules" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "rules": [
      {
        "header": "newsletter",
        "action": "fileinto",
        "folder": "Newsletters"
      },
      {
        "header": "from",
        "contains": "boss@acme.com",
        "action": "star"
      }
    ]
  }'
```

Response:

```json
{
  "rules": [
    {
      "header": "newsletter",
      "action": "fileinto",
      "folder": "Newsletters"
    }
  ]
}
```

- `discard` drops the message silently.
- `GET` the same path to read the current rules.

#### Add an extra address (alias)

`POST /api/v1/email/domains/{domain}/aliases`

Another address on the same domain that lands in an existing mailbox, at no extra cost.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `alias` | string | yes | The new name, e.g. `orders` |
| `mailbox` | string | yes | The existing mailbox it delivers into |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/aliases" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "alias": "orders",
    "mailbox": "hello"
  }'
```

Response:

```json
{
  "alias": "orders@mail.yourbrand.com",
  "delivers_to": "hello@mail.yourbrand.com"
}
```

- An alias can't be an outside address - that's forwarding.
- `409` if that name is already a mailbox.

#### Forward a mailbox

`PUT /api/v1/email/mailboxes/{domain}/{user}/forwarding`

Forward to an outside address. The target is emailed a confirm link and forwarding starts once they click it.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `target` | string | yes | The outside address |
| `keep_copy` | boolean | no | Also keep each message in this mailbox (default `true`) |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/forwarding" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "target": "you@gmail.com",
    "keep_copy": true
  }'
```

Response:

```json
{
  "target": "you@gmail.com",
  "keep_copy": true,
  "message": "We've emailed you@gmail.com a link to confirm. Forwarding starts once they click it."
}
```

- `GET` the same path shows the current forwarding; `DELETE` stops it.

#### Make a mailbox no-reply

`PUT /api/v1/email/mailboxes/{domain}/{user}/no-reply`

A send-only address: incoming mail is refused at the door, and it can still send.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `no_reply` | boolean | yes | `true` to refuse incoming mail, `false` to accept it again |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/no-reply" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "no_reply": true
  }'
```

Response:

```json
{
  "no_reply": true
}
```

#### Set a holiday auto-reply

`PUT /api/v1/email/mailboxes/{domain}/{user}/auto-reply`

Answers each sender at most once every few days and never replies to mailing lists.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `message` | string | yes | Up to 5,000 characters |
| `subject` | string | no | Subject of the reply |
| `days` | integer | no | Days between replies to the same sender, 1-30 |
| `start_date` | string | no | YYYY-MM-DD |
| `end_date` | string | no | YYYY-MM-DD |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/auto-reply" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Thanks - I'm away until Monday 5 January.",
    "subject": "Away",
    "days": 3,
    "start_date": "2026-12-20",
    "end_date": "2027-01-04"
  }'
```

Response:

```json
{
  "message": "Thanks - I'm away until Monday 5 January.",
  "subject": "Away",
  "days": 3,
  "start_date": "2026-12-20",
  "end_date": "2027-01-04"
}
```

- `GET` the same path shows it; `DELETE` turns it off.

#### Allow and block lists

`PUT /api/v1/email/mailboxes/{domain}/{user}/access-lists`

Four lists per mailbox: `in_block` (mail from these is dropped quietly), `in_allow` (when set, only these get through), `out_block` (never send to these) and `out_allow` (when set, only send to these).

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `list` | string | yes | `in_allow`, `in_block`, `out_allow` or `out_block` |
| `value` | string | no | One address or domain to add |
| `entries` | array | no | Instead of `value`: replace the whole list |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/access-lists" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "list": "in_block",
    "value": "spamdomain.example"
  }'
```

Response:

```json
{
  "lists": {
    "in_allow": [],
    "in_block": [
      "spamdomain.example"
    ],
    "out_allow": [],
    "out_block": []
  }
}
```

- `GET` the same path returns all four lists.
- `DELETE ...?list=in_block&value=spamdomain.example` removes one entry.
- `/blocks` (GET/POST/DELETE `?value=`) still works and edits `in_block`.

#### Sender name, default Bcc and signature

`PUT /api/v1/email/mailboxes/{domain}/{user}/identity`

Applied by our mail servers to every email this mailbox sends: the sender name fills the From name when you leave it blank, the default Bcc is added, and the signature is appended.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `sender_name` | string | no | Up to 100 characters |
| `default_bcc` | string | no | An address that gets a hidden copy of every send |
| `signature` | string | no | Up to 10,000 characters |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/identity" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_name": "Jane at Your Brand",
    "default_bcc": "records@yourbrand.com",
    "signature": "Jane Mensah\nYour Brand"
  }'
```

Response:

```json
{
  "sender_name": "Jane at Your Brand",
  "default_bcc": "records@yourbrand.com",
  "signature": "Jane Mensah\nYour Brand"
}
```

- `GET` reads it, `DELETE` clears all three.
- To send one email exactly as you built it, pass `use_identity: false` on that send.

#### Import old mail

`POST /api/v1/email/mailboxes/{domain}/{user}/import`

Copies a whole old mailbox in, in the background: folders mapped, read and starred flags and dates kept, already-copied messages skipped.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `provider` | string | yes | `gmail`, `outlook`, `yahoo` or `icloud` |
| `source_email` | string | yes | The old address |
| `app_password` | string | yes | An app password the owner creates at the old provider (not their normal password) |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/import" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "gmail",
    "source_email": "you@gmail.com",
    "app_password": "abcd efgh ijkl mnop"
  }'
```

Response:

```json
{
  "import": {
    "status": "running",
    "source_email": "you@gmail.com"
  }
}
```

- `GET` the same path shows progress.
- We pass the app password on and never store it.

#### Webhooks for a mailbox

`POST /api/v1/email/mailboxes/{domain}/{user}/webhooks`

Get an HTTPS POST when mail arrives in this mailbox, signed with your secret.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `url` | string | yes | `https://` endpoint |
| `events` | array | no | Which events to send |
| `secret` | string | no | Used to sign each delivery |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/webhooks" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://yourapp.com/webhooks/mail",
    "events": [
      "received"
    ],
    "secret": "your-signing-secret"
  }'
```

Response:

```json
{
  "id": "wh_\u2026",
  "url": "https://yourapp.com/webhooks/mail"
}
```

- `GET` lists them, `DELETE ...?id=wh_…` removes one.

#### AI-agent token for an existing mailbox

`POST /api/v1/email/mailboxes/{domain}/{user}/agent-tokens`

A token an AI agent uses for this one mailbox, limited to what you allow. With `send-with-approval`, its sends wait for a person to approve them.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `scopes` | array | yes | Any of `read`, `draft`, `send`, `send-with-approval` (not both sends) |
| `label` | string | no | A name to tell tokens apart |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/agent-tokens" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Support bot",
    "scopes": [
      "read",
      "draft",
      "send-with-approval"
    ]
  }'
```

Response:

```json
{
  "email": "hello@mail.yourbrand.com",
  "id": "at_\u2026",
  "label": "Support bot",
  "scopes": [
    "draft",
    "read",
    "send-with-approval"
  ],
  "agent_token": "agt_\u2026",
  "agent_connect": {
    "mcp": {
      "url": "https://mail.sasusync.com:4300/mcp"
    }
  }
}
```

- `agent_token` is shown exactly once.
- `GET` lists tokens (never their values); `DELETE ...?id=at_…` revokes one.
- Every draft, send, approval and rejection is kept in a 30-day action log.

#### Emails waiting for approval

`GET /api/v1/email/mailboxes/{domain}/{user}/outbox`

Everything this mailbox's AI agents sent with a `send-with-approval` token, held until a person approves it, plus drafts they saved. Nothing here has been sent.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/outbox" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "outbox": [
    {
      "id": "ob_7f3a",
      "mailbox": "hello@mail.yourbrand.com",
      "to": [
        "customer@example.com"
      ],
      "subject": "Your refund",
      "status": "pending",
      "created_at": "2026-11-15T09:12:00Z"
    }
  ]
}
```

- `GET .../outbox/{id}` returns one held email in full, body included.

#### Approve or reject a held email

`POST /api/v1/email/mailboxes/{domain}/{user}/outbox/{id}/{action}`

`approve` sends a held email now, `reject` makes sure it is never sent, and `send` sends a draft. `DELETE .../outbox/{id}` discards it.

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/outbox/ob_7f3a/approve" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "message": "Approved - it's on its way."
}
```

- An approved email goes out through the normal signed, metered path, exactly as if the agent had been allowed to send it.

#### What the AI agents did

`GET /api/v1/email/mailboxes/{domain}/{user}/action-log`

Every draft, send, approval and rejection by this mailbox's agents in the last 30 days.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/action-log" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "window_days": 30,
  "actions": [
    {
      "action": "submitted_for_approval",
      "subject": "Your refund",
      "at": "2026-11-15T09:12:00Z"
    }
  ]
}
```

#### Mailbox storage

`GET /api/v1/email/mailboxes/{domain}/{user}/storage`

How much of the mailbox's space is used.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/mailboxes/mail.yourbrand.com/hello/storage" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "used_bytes": 12557,
  "limit_bytes": 2147483648,
  "messages": 2,
  "percent": 0.0
}
```

- Each mailbox has 2 GB.

#### Create an agent mailbox

`POST /api/v1/email/mailboxes`

Give an AI agent its own address on your domain - send, receive, search, thread, label and extract over the API, webhooks and a hosted MCP server.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `domain` | string | yes | A verified `hosting`-mode domain on this account |
| `user` | string | yes | The local part, e.g. `support-bot` |
| `agent` | boolean | yes | `true` |
| `webhook_url` | string | no | `https://` URL that receives each inbound message |
| `webhook_include_body` | boolean | no | Include the full `raw_email` in each webhook |
| `webmail` | boolean | no | Also give a person a browser inbox over this mailbox |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/mailboxes" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "mail.yourbrand.com",
    "user": "support-bot",
    "agent": true,
    "webhook_url": "https://your-agent.example.com/inbound",
    "webhook_include_body": true
  }'
```

Response:

```json
{
  "email": "support-bot@mail.yourbrand.com",
  "agent_token": "agt_\u2026",
  "temp_password": "\u2026",
  "imap": {
    "host": "mail.sasusync.com",
    "port": 993,
    "security": "SSL/TLS"
  },
  "smtp": {
    "host": "mail.sasusync.com",
    "port": 587,
    "security": "STARTTLS"
  },
  "webmail": {},
  "agent_connect": {
    "api_base": "https://mail.sasusync.com:4100",
    "auth_header": {
      "X-Api-Key": "agt_\u2026"
    },
    "mcp": {
      "url": "https://mail.sasusync.com:4300/mcp",
      "config": {
        "mcpServers": {
          "mail": {
            "url": "https://mail.sasusync.com:4300/mcp",
            "headers": {
              "X-Api-Key": "agt_\u2026"
            }
          }
        }
      }
    },
    "webmail_url": "https://webmail.sasusync.com",
    "tools": [
      "send_email",
      "list_messages",
      "get_message",
      "get_attachments",
      "extract_message",
      "set_labels",
      "list_webhooks",
      "create_webhook",
      "delete_webhook"
    ]
  }
}
```

- **The agent authenticates with the token alone**: `X-Api-Key: agt_…`, no secret. It is scoped to this one address, so a leaked token can't touch any other mailbox. `GET /v1/me` on the API base returns the agent's own address.
- **Send:** `POST /v1/emails` with `from` equal to the agent's own address. To thread a reply pass `in_reply_to` (and optionally `references`) and store the returned `message_id`. Track delivery with `GET /v1/emails/{id}`. Pass `idempotency_key` (or an `Idempotency-Key` header) for exactly-once retries.
- **Read:** `GET /v1/mailboxes/{address}/messages` - newest first, paginated (`limit`, `cursor`). Filter with `q` (+ `body=1` to search bodies), `thread_id`, or `label`. One message: `…/messages/{id}`, plus `/raw` and `/attachments`. Every message has a stable `thread_id`, a `direction` (`received`/`sent`) and `labels`; your own sent mail is indexed with what you receive, so a `thread_id` query returns the whole back-and-forth.
- **Triage:** `POST …/messages/{id}/labels` with `{add, remove, set}` (tags like `read`, `urgent`, `handled`). `GET …/messages/{id}/extract` returns AI-extracted `summary`, `intent`, `urgency`, `sender_name`, `action_items`, `entities`, `requested_datetime` and `sentiment`, cached so asking again is free.
- **Trust:** each received message carries `spf`, `dkim` and `dmarc` results (`pass`/`fail`/`none`) stamped by our mail servers - a forged header inside the message is ignored. Match and display on `header_from`; a spoof shows a plausible `header_from` with `dmarc` not `pass`.
- **Push:** inbound webhooks are POSTed as JSON with an `X-Inboxi-Event` header and, when signed, `X-Inboxi-Signature: hex(HMAC-SHA256(secret, raw_body))`. At-least-once: retried at 30s, 2m, 10m, 1h, 6h, then dead-lettered; recover with `GET /v1/webhooks/{id}/deliveries` and `POST …/replay`. The event `id` is stable - use it to de-duplicate. Manage hooks with `GET/POST/DELETE /v1/mailboxes/{address}/webhooks`.
- **Stream:** for zero latency and no public URL, open a WebSocket to `/v1/mailboxes/{address}/stream` with the same `X-Api-Key` (or `?token=agt_…`). You get `{"type":"connected"}`, then an `email.received` event per inbound message.
- **MCP:** point any MCP client (Claude, Cursor, Windsurf, LangGraph, CrewAI…) at the `agent_connect.mcp` URL with the token as `Authorization: Bearer agt_…` - zero install, and it discovers its own address from the token. `agent_connect.mcp.config` is a ready `mcpServers` block for Claude Desktop, Cursor and Windsurf, and `agent_connect.mcp.claude_code` is the one-line Claude Code command. Nine tools: `send_email`, `list_messages`, `get_message`, `get_attachments`, `extract_message`, `set_labels`, `list_webhooks`, `create_webhook`, `delete_webhook`.
- Deleting a mailbox revokes its tokens, removes its webhooks and purges its inbox and labels. Tokens are stored only as hashes on our side; we cannot show one again - create a fresh mailbox if it is lost.

#### Let agents create their own mailboxes

`POST /api/v1/email/domains/{domain}/onboarding-keys`

Mint a revocable, quota-limited key so an agent can provision its own mailbox on this domain - no open signup, nothing else the key can do.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `max_mailboxes` | integer | yes | How many mailboxes this key may create (1-1000) |
| `prefix` | string | no | Every mailbox it creates is named with this prefix, e.g. `bot-` gives `bot-alpha`. Letters, numbers and hyphens, up to 20. |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/onboarding-keys" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "max_mailboxes": 50,
    "prefix": "bot-"
  }'
```

Response:

```json
{
  "id": "okey-1",
  "onboarding_key": "onb_\u2026",
  "max_mailboxes": 50,
  "prefix": "bot-",
  "remaining": 50,
  "onboard": {
    "url": "https://mail.sasusync.com:4100/v1/onboard",
    "method": "POST",
    "auth_header": "X-Api-Key: <onboarding_key>",
    "body": {
      "user": "alpha"
    }
  }
}
```

- `onboarding_key` (`onb_…`) is shown exactly once. The agent then calls `POST /v1/onboard` on the API base with `X-Api-Key: onb_…` and `{"user": "alpha"}` and gets back `{email, agent_token, remaining}` - its own mailbox and token.
- The key enforces its quota and prefix, is inert for anything else, and is revocable.
- `402` if `max_mailboxes` is more than your plan still has room for - a key can never be used to get past the plan's mailbox limit.
- `409` if the domain isn't a verified `hosting`-mode domain.

#### List onboarding keys

`GET /api/v1/email/domains/{domain}/onboarding-keys`

Each key's id, prefix and remaining quota - never the key itself.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/onboarding-keys" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "onboarding_keys": [
    {
      "id": "okey-1",
      "prefix": "bot-",
      "max_mailboxes": 50,
      "remaining": 49
    }
  ]
}
```

#### Revoke an onboarding key

`DELETE /api/v1/email/domains/{domain}/onboarding-keys/{key_id}`

Stops it creating any more mailboxes. Mailboxes it already created keep working.

```bash
curl -X DELETE "https://sms.sasusync.com/api/v1/email/domains/mail.yourbrand.com/onboarding-keys/okey-1" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "message": "Onboarding key revoked."
}
```

### International SMS

#### Countries we send to, and what each costs

`GET /api/v1/international/countries`

Every destination that is open, with the SMS credits one message part costs there. The same `/api/v1/send` call sends abroad: nothing else changes.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/international/countries" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "enabled": true,
  "unit": "sms credits per message segment",
  "countries": [
    {
      "country_code": "GB",
      "dial_code": "+44",
      "name": "United Kingdom",
      "credits_per_segment": 25
    }
  ]
}
```

- Write a number outside Ghana with a `+` and its country code (`+447555834656`). A number that begins like a Ghana number (`024...`, `+23324...`) is sent as a Ghana SMS at one credit.
- An international message costs the country's credits per segment instead of 1, taken from SMS credits first and then from the main balance, exactly like a Ghana one. `balance.deducted` in the send response is what was billed.
- Your sender ID registers itself for sending abroad the first time you send with it. If we have switched on approval first, until it is approved a send to a number abroad returns `403` and says so; Ghana numbers are unaffected. Ask for it in the portal.
- A country we have switched off returns `400` naming the country.
- A failed international message is refunded like any other.

#### Price a send before making it

`POST /api/v1/international/quote`

Tells you how many credits a list of numbers would cost, split by country.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `recipients` | array | yes | Numbers in any format we accept |
| `message` | string | no | Used to count message parts |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/international/quote" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "recipients": [
      "0241234567",
      "+447555834656",
      "+2348031234567"
    ],
    "message": "Hello"
  }'
```

Response:

```json
{
  "success": true,
  "segments": 1,
  "local": 1,
  "international": [
    {
      "dial": "44",
      "country": "United Kingdom",
      "count": 1,
      "credits_each": 25,
      "available": true
    }
  ],
  "invalid": [],
  "invalid_count": 0,
  "total_credits": 51
}
```

- Nothing is sent or charged.

### Numbers

#### Your dedicated numbers

`GET /api/v1/numbers`

A dedicated number sends texts under its own number and receives replies.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/numbers" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "numbers": [
    {
      "id": 3,
      "phone_number": "+14155550100",
      "country_code": "US",
      "friendly_name": "Support",
      "status": "active",
      "monthly_price": "84.00",
      "auto_renew": true,
      "renews_at": "2026-12-21T00:00:00",
      "received": 12
    }
  ]
}
```

- Send from one by using the number as `sender` on `/api/v1/send` (for example `"sender": "+14155550100"`). It can send to Ghana and abroad.
- Replies are stored and posted to your webhook; see `GET /api/v1/inbox`.

#### Find a number to lease

`GET /api/v1/numbers/available?country=GB`

Numbers you can lease in a country, with the monthly price in your account currency.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `country` | string | yes | Two-letter country code, for example `US`, `GB`, `NG` |

```bash
curl -X GET "https://sms.sasusync.com/api/v1/numbers/available?country=GB" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "country": "GB",
  "numbers": [
    {
      "phone_number": "+447457412139",
      "country_code": "GB",
      "type": "National",
      "sms": true,
      "mms": false,
      "voice": true,
      "monthly_price": "84"
    }
  ]
}
```

#### Lease a number

`POST /api/v1/numbers/lease`

Takes the first month from your main balance, then renews monthly.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `phone_number` | string | yes | A number returned by the search |
| `country_code` | string | yes | Its two-letter country code |
| `friendly_name` | string | no | A label for you |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/numbers/lease" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phone_number": "+447457412139",
    "country_code": "GB",
    "friendly_name": "Support"
  }'
```

Response:

```json
{
  "success": true,
  "id": 3,
  "phone_number": "+447457412139",
  "monthly_price": "84.00",
  "renews_at": "2026-12-21T00:00:00"
}
```

- If the number cannot be leased you are not charged. `402` means the main balance is short; the message says by how much.
- Each month the price is taken again. Turn renewal off in the portal and the number stops at the end of the month it is paid for.

#### Messages received on your numbers

`GET /api/v1/inbox?limit=20`

Newest first. The same messages are posted to your webhook as they arrive.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `number_id` | integer | no | Only this number's messages |
| `limit` | integer | no | Up to 500, default 100 |

```bash
curl -X GET "https://sms.sasusync.com/api/v1/inbox?limit=20" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "success": true,
  "messages": [
    {
      "id": 9,
      "number_id": 3,
      "from_number": "+233241234567",
      "to_number": "+14155550100",
      "body": "Hello, I want to order",
      "received_at": "2026-11-21T10:30:00"
    }
  ]
}
```

- Webhook event: `sms.inbound` with `number`, `from`, `message` and `received_at`, signed the same way as delivery reports.

### Reseller

#### Your reseller account

`GET /api/v1/reseller/me`

Your credits, your wholesale price and the lowest price you may charge a client.

```bash
curl -X GET "https://sms.sasusync.com/api/v1/reseller/me" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "credits": 12000,
  "clients": 3,
  "wholesale_rate": "0.0395",
  "minimum_client_price": "0.0395",
  "tiers": [
    {
      "min_credits": 10000,
      "price_per_sms": "0.0420"
    },
    {
      "min_credits": 50000,
      "price_per_sms": "0.0395"
    }
  ],
  "ghana_only": true
}
```

- Needs a reseller key. An approved reseller is switched on for this API by us; any other key gets `403`.
- Calls are limited per key (a burst of 60, then one a second). Over the limit you get `429` and a `Retry-After` header.

#### Buy credits at your wholesale price

`POST /api/v1/reseller/purchase`

Returns a checkout link; credits land when the payment is confirmed.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `amount` | number | yes | Cedis to spend. More money reaches a bigger pack and a lower price per SMS |
| `redirect_url` | string | no | Where the buyer returns after paying |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/reseller/purchase" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "2000.00"
  }'
```

Response:

```json
{
  "success": true,
  "external_ref": "TOPUP_ab12",
  "payment_url": "https://pay.example/checkout/ab12",
  "credits": 50632,
  "price_per_sms": "0.0395"
}
```

- Price per SMS depends on the pack your money reaches: the cheapest tier whose pack size you reach is used (no in-between prices). Below the smallest pack you pay the smallest tier's price. Credits are rounded down.
- No price is ever below 0.0365 per SMS.

#### Create a client account

`POST /api/v1/reseller/clients`

Creates the account and emails the client a link to set their own password.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `company` | string | yes | Up to 120 characters, no < or > |
| `email` | string | yes | Must be unique on the platform |
| `phone` | string | yes | Must be unique on the platform |
| `credits` | integer | no | Moved from your balance |
| `price` | number | no | What this client pays per SMS. Never below what you pay |
| `send_invite` | boolean | no | Default true |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/reseller/clients" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "company": "Accra Bakery",
    "email": "ama@accrabakery.example",
    "phone": "0241234567",
    "credits": 200,
    "price": "0.0600",
    "send_invite": true
  }'
```

Response:

```json
{
  "success": true,
  "id": 412,
  "invite_sent": true,
  "credits": 200
}
```

- No password is ever returned. `409` when the email or phone is already registered.
- A client sees only their own account, never your prices or your other clients.

#### List your clients

`GET /api/v1/reseller/clients?page=1&per_page=50`

Your clients only, newest first.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `page` | integer | no | From 1 |
| `per_page` | integer | no | Up to 100 |

```bash
curl -X GET "https://sms.sasusync.com/api/v1/reseller/clients?page=1&per_page=50" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "page": 1,
  "per_page": 50,
  "total": 1,
  "clients": [
    {
      "id": 412,
      "company": "Accra Bakery",
      "email": "ama@accrabakery.example",
      "phone": "0241234567",
      "credits": 200,
      "price_per_sms": "0.0600",
      "self_topup_enabled": true,
      "created_at": "2026-12-01 10:00:00"
    }
  ]
}
```

- `GET /api/v1/reseller/clients/{id}` returns one client. A client that is not yours is `404`.

#### Send credits to a client

`POST /api/v1/reseller/clients/412/transfer`

Moves credits from your balance to the client, all or nothing.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `credits` | integer | yes | 1 to 10,000,000 |
| `idempotency_key` | string | yes | 8-64 letters, digits, - or _ (or send an `Idempotency-Key` header) |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/reseller/clients/412/transfer" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "credits": 500,
    "idempotency_key": "order-8841"
  }'
```

Response:

```json
{
  "success": true,
  "replayed": false,
  "credits": 500,
  "reseller_balance": 4400,
  "client_balance": 700
}
```

- Repeating a call with the same key changes nothing and returns `replayed: true`. The same key with another amount is `409`.
- `402` if you do not have enough free credits. Credits held for sends in progress are not available.

#### Take unspent credits back

`POST /api/v1/reseller/clients/412/reclaim`

Returns credits you sent that the client has not used.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `credits` | integer | yes | At most what is left of the credits you sent |
| `idempotency_key` | string | yes | As for transfer |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/reseller/clients/412/reclaim" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "credits": 100,
    "idempotency_key": "reclaim-8842"
  }'
```

Response:

```json
{
  "success": true,
  "replayed": false,
  "credits": 100,
  "reseller_balance": 4500,
  "client_balance": 600
}
```

- Credits the client bought themselves, or has already spent, cannot be reclaimed (`409`).

#### Set a client's price per SMS

`PUT /api/v1/reseller/clients/412/price`

What this client pays for each SMS when buying credits.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `price` | number | yes | Cedis per SMS |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/reseller/clients/412/price" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "price": "0.0650"
  }'
```

Response:

```json
{
  "success": true,
  "id": 412,
  "price_per_sms": "0.0650"
}
```

- `422` if the price is below what you pay for credits, or below 0.0365.

#### Allow or block client self top-up

`PUT /api/v1/reseller/clients/412/self-topup`

Whether the client may buy credits through our checkout.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `enabled` | boolean | yes | false sends the client to you for top-ups |

```bash
curl -X PUT "https://sms.sasusync.com/api/v1/reseller/clients/412/self-topup" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'
```

Response:

```json
{
  "success": true,
  "id": 412,
  "self_topup_enabled": false
}
```

- To take payment from clients yourself (your own gateway, MoMo or bank), turn this off, collect the money, then call the transfer endpoint to give them credits. Collecting that money is your responsibility.

#### Usage per client

`GET /api/v1/reseller/usage?days=30`

SMS sent, credits received and reclaimed for each client.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `days` | integer | no | 1 to 365 |

```bash
curl -X GET "https://sms.sasusync.com/api/v1/reseller/usage?days=30" \
  -H "X-API-Key: $SASUSYNC_API_KEY"
```

Response:

```json
{
  "days": 30,
  "your_credits": 4500,
  "clients": [
    {
      "id": 412,
      "company": "Accra Bakery",
      "credits": 600,
      "sms_sent": 90,
      "credits_received": 500,
      "credits_reclaimed": 100
    }
  ]
}
```

#### Import many clients at once

`POST /api/v1/reseller/clients/bulk`

Up to 1000 clients per call. Each row gets its own result, so one bad row never stops the rest.

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `clients` | array | yes | Up to 1000 rows of company, email, phone, optional credits and price |
| `send_invites` | boolean | no | Default false, so existing customers are not emailed until you choose |

```bash
curl -X POST "https://sms.sasusync.com/api/v1/reseller/clients/bulk" \
  -H "X-API-Key: $SASUSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "send_invites": false,
    "clients": [
      {
        "company": "Accra Bakery",
        "email": "ama@accrabakery.example",
        "phone": "0241234567",
        "credits": 50
      }
    ]
  }'
```

Response:

```json
{
  "success": true,
  "summary": {
    "created": 1
  },
  "results": [
    {
      "row": 0,
      "status": "created",
      "id": 412,
      "credits": 50
    }
  ]
}
```

- Row status is `created`, `exists` (already your client, untouched), `duplicate` (repeated in this call), `conflict` (email or phone registered elsewhere; nothing is changed or revealed) or `error`.
- Counts as 20 calls against your rate limit.

---

## Webhooks

Optional. Set a URL against an API key in the portal and a signing secret is
issued at the same moment, shown once. Without a webhook, delivery outcomes are
read from the portal instead — sending works either way.

Per-message events: `sent` (accepted by the network), `delivered` (reached the
handset), `failed` (wrong number, phone off, blocked), `expired` (never delivered
in time).

```json
{
  "event": "delivered",
  "timestamp": "2026-08-02T10:05:15.123456",
  "data": {
    "message_id": "88cc01a5-ca7a-47b8-8fff-b6bcd1fcbe29",
    "recipient": "233552148347",
    "status": "delivered"
  }
}
```

Account-level events, sent to every key on the account that has a webhook set —
these are not tied to one message, so `data.message_id` is absent:

- `low_balance` — SMS credits or main balance just crossed the low threshold.
  Fires once per episode; the next one waits for a top-up in between.
- `topup_succeeded` — a payment settled and a balance was credited.

```json
{
  "event": "low_balance",
  "data": {
    "account_id": 42,
    "sms_credits": 12,
    "wallet_balance": "1.50",
    "currency": "GHS"
  }
}
```

```json
{
  "event": "topup_succeeded",
  "data": {
    "account_id": 42,
    "kind": "main",
    "amount": "50.00",
    "credits": 0,
    "currency": "GHS",
    "sms_credits": 12,
    "wallet_balance": "51.50",
    "reference": "SASU-abc123"
  }
}
```

Requirements for the receiving endpoint:

- HTTPS only. An `http://` URL is refused when saving it.
- Answer `200` within 10 seconds; do the real work afterwards.
- Verify `X-Webhook-Signature` — the hex HMAC-SHA256 of the **raw request body**
  under the signing secret. The verification function is in the client above.
- Expect repeats and out-of-order delivery. Key on `data.message_id`.

Delivery reports are best-effort: not every network reports back. Treat `sent` as
"handed over", not "read", and never block your own flow waiting for `delivered`.

---

## Errors

Failures return the HTTP status and a `detail` string written for a person.

| Code | Meaning | What to do |
| --- | --- | --- |
| `400` | Bad request | Fix the request. Do not retry unchanged. |
| `401` | Invalid or missing API key | Check the header. The key may have been revoked. |
| `402` | Out of credit, or this key's own usage cap is reached | The message says which. Top up, or raise the cap in the portal. |
| `403` | Sender not approved, account suspended, or this key is IP-restricted and the call came from an address not on its list | The message names the sender IDs that may be used, or the address refused. |
| `404` | Not found | The id does not exist, or belongs to someone else. |
| `409` | Already taken | Usually a sender ID someone else holds. |
| `422` | Validation failed | The body names the offending field. |
| `429` | Too many requests, or an OTP is still pending for that number | Back off and retry. |
| `500` | Server error | Retry with backoff. |
| `503` | Upstream unavailable | Retry with backoff. |

---

## Integration checklist

- [ ] API key read from the environment, not committed.
- [ ] Every call goes through one client module, so retries and errors are handled once.
- [ ] Built and tested against `/smssandbox/v1/send` before any live send.
- [ ] A sender ID is registered and shows `approved` before switching to `/api/v1/send`.
- [ ] Retries cover only 429 and 5xx, with backoff.
- [ ] A timeout triggers a status lookup, never a blind resend.
- [ ] Long messages are counted in parts, and `balance.deducted` is what gets logged.
- [ ] If webhooks are used: raw-body signature check, 200 within 10 seconds, repeats are no-ops.
- [ ] The balance is checked on a schedule and someone is alerted before it hits zero.

