Pagination
Every list endpoint returns the same envelope, even short lists such as devices or webhooks:
{ "data": [ { "id": "msg_q8v2k4n6p1r3t5w7y9z0b2c4", "status": "delivered" }, { "id": "msg_h3j5l7n9q2s4u6w8y1a3c5e7", "status": "sent" } ], "nextCursor": "bXNnX2gzajVsN245cTJzNHU2dzh5MWEzYzVlNw"}nextCursor is null on the last page. Lists are ordered newest first.
Parameters
Section titled “Parameters”| Query | Default | Range | Description |
|---|---|---|---|
limit |
50 | 1 to 200 | Items per page. |
cursor |
nextCursor from the previous page. Leave it out for the first page. |
Treat the cursor as an opaque string: pass it back exactly as received. A cursor the API did not issue returns 400 invalid_cursor. Keep the same filters on every page; changing them mid-way gives inconsistent results.
Cursor paging is stable while new items arrive. A message created while you page appears at the start of the list, so it never shifts the pages you are reading.
Walk every page
Section titled “Walk every page”cursor=""while :; do page=$(curl -s "https://api.smsfabric.com/v1/messages?status=failed&limit=200${cursor:+&cursor=$cursor}" \ -H "X-Api-Key: $SMSFABRIC_API_KEY") echo "$page" | jq -r '.data[] | "\(.id) \(.errorCode)"' cursor=$(echo "$page" | jq -r '.nextCursor // empty') [ -z "$cursor" ] && breakdoneimport { SMSFabric } from '@smsfabric/sdk';
const sf = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
// listAll follows nextCursor for you.for await (const message of sf.messages.listAll({ status: 'failed', limit: 200 })) { console.log(message.id, message.errorCode);}
// Or one page at a time:const first = await sf.messages.list({ limit: 50 });if (first.nextCursor) { const second = await sf.messages.list({ limit: 50, cursor: first.nextCursor }); console.log(second.data.length);}import osimport requests
def list_all(path: str, **params): headers = {"X-Api-Key": os.environ["SMSFABRIC_API_KEY"]} params = {"limit": 200, **params} while True: res = requests.get(f"https://api.smsfabric.com{path}", headers=headers, params=params, timeout=30) res.raise_for_status() page = res.json() yield from page["data"] if not page["nextCursor"]: return params["cursor"] = page["nextCursor"]
for message in list_all("/v1/messages", status="failed"): print(message["id"], message["errorCode"])<?phpfunction listAll(string $path, array $params = []): Generator { $params += ['limit' => 200]; do { $ch = curl_init('https://api.smsfabric.com' . $path . '?' . http_build_query($params)); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => ['X-Api-Key: ' . getenv('SMSFABRIC_API_KEY')], CURLOPT_RETURNTRANSFER => true, ]); $page = json_decode(curl_exec($ch), true); yield from $page['data']; $params['cursor'] = $page['nextCursor']; } while ($page['nextCursor'] !== null);}
foreach (listAll('/v1/messages', ['status' => 'failed']) as $message) { echo $message['id'] . ' ' . $message['errorCode'] . "\n";}Paginated endpoints
Section titled “Paginated endpoints”These take limit and cursor: GET /v1/messages, GET /v1/verifications, GET /v1/contacts, GET /v1/contact-groups, GET /v1/contact-imports, GET /v1/templates, GET /v1/campaigns, GET /v1/blacklist, GET /v1/webhooks/:id/deliveries and GET /v1/audit.
These return the whole list in one page, with nextCursor: null: GET /v1/devices, GET /v1/pools, GET /v1/webhooks, GET /v1/api-keys, GET /v1/org/members and GET /v1/org/invitations.
For a full copy of your message log, GET /v1/messages/export.csv streams every matching row in one response.