Campaign Results API (/v1/campaigns)
The Campaign Results API in Mahadata provides read-only, server-to-server access using an API Key (Authorization: Bearer <API_KEY>) to reconcile campaign delivery outcomes without relying on webhooks. These endpoints allow external systems to list campaigns, list campaign runs along with the same precomputed summary counters shown in the portal, and inspect per-recipient delivery statuses. All data is automatically scoped to the tenant account that owns the API Key.
Authentication & Rate Limits
Section titled “Authentication & Rate Limits”Include the standard Bearer API Key header on every request:
Authorization: Bearer $API_KEYThe campaign results endpoints use your standard account API key and do not require any additional scope.
Rate Limit: Up to 60 requests per minute per API key across the campaign results endpoints (/v1/campaigns, /v1/campaigns/{campaign_id}/runs, and /v1/campaign-runs/{run_id}/recipients). When this limit is exceeded, the server responds with HTTP 429 Too Many Requests.
1. List Campaigns (GET /v1/campaigns)
Section titled “1. List Campaigns (GET /v1/campaigns)”Returns campaigns belonging to your account ordered from newest to oldest (created_at DESC, id DESC) using keyset cursor pagination.
Query Parameters (GET /v1/campaigns)
Section titled “Query Parameters (GET /v1/campaigns)”| Parameter | Type | Default | Description |
|---|---|---|---|
after | string | — | Next-page cursor ("<rfc3339>|<uuid>") taken from next_cursor in the previous response |
limit | integer | 50 | Page size (automatically clamped to 1..=100) |
Example Request (GET /v1/campaigns)
Section titled “Example Request (GET /v1/campaigns)”curl -sS "https://messaging.mahadata.io/v1/campaigns?limit=50" \ -H "Authorization: Bearer $API_KEY"Example Response (GET /v1/campaigns)
Section titled “Example Response (GET /v1/campaigns)”{ "data": [ { "id": "00000000-0000-4000-8000-000000000001", "name": "Year-End Promo", "status": "active", "created_at": "2026-11-10T08:00:00Z" } ], "has_more": true, "next_cursor": "2026-11-10T08:00:00.000000Z|00000000-0000-4000-8000-000000000001"}Important: the
next_cursorof the campaign and run lists contains a|character and must be URL-encoded when passed as theafterparameter (for example withcurl -G --data-urlencode "after=$CURSOR").
2. List Campaign Runs (GET /v1/campaigns/{campaign_id}/runs)
Section titled “2. List Campaign Runs (GET /v1/campaigns/{campaign_id}/runs)”Returns runs for a specific campaign (created_at DESC, id DESC) together with precomputed delivery and customer reply counters.
Path & Query Parameters (GET /v1/campaigns/{campaign_id}/runs)
Section titled “Path & Query Parameters (GET /v1/campaigns/{campaign_id}/runs)”| Parameter | Location | Type | Default | Description |
|---|---|---|---|---|
campaign_id | path | UUID | Required | Campaign UUID |
after | query | string | — | Next-page cursor ("<rfc3339>|<uuid>") from next_cursor |
limit | query | integer | 50 | Page size (automatically clamped to 1..=100) |
Example Request (GET /v1/campaigns/{campaign_id}/runs)
Section titled “Example Request (GET /v1/campaigns/{campaign_id}/runs)”curl -sS "https://messaging.mahadata.io/v1/campaigns/00000000-0000-4000-8000-000000000001/runs?limit=20" \ -H "Authorization: Bearer $API_KEY"Example Response (GET /v1/campaigns/{campaign_id}/runs)
Section titled “Example Response (GET /v1/campaigns/{campaign_id}/runs)”{ "data": [ { "id": "00000000-0000-4000-8000-000000000002", "status": "completed", "scheduled_for": "2026-11-10T08:00:00Z", "started_at": "2026-11-10T08:00:02Z", "completed_at": "2026-11-10T08:15:10Z", "created_at": "2026-11-10T08:00:00Z", "counts": { "total": 1000, "sent": 980, "delivered": 950, "read": 610, "failed": 20, "replied": 45 }, "stats_computed_at": "2026-11-10T08:16:00Z", "stats_final": false } ], "has_more": false, "next_cursor": null}How counts Relates to Portal Numbers & What null Means
Section titled “How counts Relates to Portal Numbers & What null Means”- Portal Alignment: The
countsobject (total,sent,delivered,read,failed,replied) is read directly from the same precomputed campaign run statistics snapshot used by the Mahadata portal campaign run list and report views. - When
countsisnull: If a run was just created or scheduled and its statistics snapshot has not been computed yet by the background scheduler,counts,stats_computed_at, andstats_finalare returned asnull. This endpoint never triggers a synchronous table scan so responses remain fast and predictable. - Freshness (
stats_computed_at&stats_final):stats_computed_atindicates when the snapshot was last refreshed (UTC). While a run is active or still within the read-receipt reconciliation window,stats_finalisfalseand counters continue refreshing periodically until finalized (stats_final: true).
3. List Campaign Run Recipients (GET /v1/campaign-runs/{run_id}/recipients)
Section titled “3. List Campaign Run Recipients (GET /v1/campaign-runs/{run_id}/recipients)”Returns per-recipient delivery outcomes for a campaign run ordered by phone number (recipient_e164 ASC), using an opaque cursor token valid for 1 hour.
Path & Query Parameters (GET /v1/campaign-runs/{run_id}/recipients)
Section titled “Path & Query Parameters (GET /v1/campaign-runs/{run_id}/recipients)”| Parameter | Location | Type | Default | Description |
|---|---|---|---|---|
run_id | path | UUID | Required | Campaign run UUID |
status | query | string | — | Cumulative status filter: pending, sent, delivered, read, failed, or replied |
after | query | string | — | Opaque cursor token from next_cursor in the previous response (valid for 1 hour) |
limit | query | integer | 100 | Page size (automatically clamped to 1..=1000) |
Example Request (GET /v1/campaign-runs/{run_id}/recipients)
Section titled “Example Request (GET /v1/campaign-runs/{run_id}/recipients)”curl -sS "https://messaging.mahadata.io/v1/campaign-runs/00000000-0000-4000-8000-000000000002/recipients?status=failed&limit=100" \ -H "Authorization: Bearer $API_KEY"Example Response (GET /v1/campaign-runs/{run_id}/recipients)
Section titled “Example Response (GET /v1/campaign-runs/{run_id}/recipients)”{ "data": [ { "phone": "+6281234567890", "message_id": "wamid.HBgNNjI4MTIzNDU2Nzg5MBUCABIYFDNB", "status": "failed", "error_code": "131026", "error_title": "Message undeliverable", "sent_at": "2026-11-10T08:01:12Z", "delivered_at": null, "read_at": null, "failed_at": "2026-11-10T08:01:15Z" } ], "has_more": false, "next_cursor": null}Row status vs. the status= Filter
Section titled “Row status vs. the status= Filter”On each recipient item in data, the status field is mutually exclusive and reports the highest delivery progress reached by that recipient according to the following precedence:
Row status Value | Resolution Rule (Highest Progress Wins) |
|---|---|
read | read_at is not null |
delivered | read_at is null and delivered_at is not null |
failed | read_at and delivered_at are null, and failed_at is not null |
sent | Only sent_at is not null (not yet delivered, read, or failed) |
pending | sent_at, delivered_at, read_at, and failed_at are all null |
By contrast, the status= query parameter is cumulative so that the total number of rows matching each filter equals the corresponding counter in the run’s counts object:
status= Filter Value | Matching Row Predicate | Matches counts Field |
|---|---|---|
pending | sent_at IS NULL and failed_at IS NULL | no equivalent counter |
sent | sent_at IS NOT NULL (includes rows later delivered or read) | counts.sent |
delivered | delivered_at IS NOT NULL (includes rows later read) | counts.delivered |
read | read_at IS NOT NULL | counts.read |
failed | failed_at IS NOT NULL | counts.failed |
replied | Recipient replied to the campaign (first_reply_at IS NOT NULL) | counts.replied |
Pagination Rules & Windowed Filtered Scans (Important)
Section titled “Pagination Rules & Windowed Filtered Scans (Important)”All three endpoints return the same pagination envelope:
data: Array of items for the current page.has_more: Boolean indicating whether additional pages remain.next_cursor: Cursor string to pass asafteron the next request, ornullwhenhas_moreisfalse.
Short or Empty Pages When Filtering with status=:
To keep database queries fast on multi-million-recipient runs without performing unbounded scans, filtered /recipients requests inspect at most 10,000 primary-key rows per call:
- If fewer than
limitmatching rows (or0matching rows) appear within the 10,000-row scan window, the API returns the matching rows found in that window (which may be shorter thanlimitor an empty[]array) together withhas_more: trueand anext_cursoradvancing past the 10,000-row window. - Clients must keep following
next_cursoruntilnext_cursorisnull(has_more: false), and must not stop early merely becausedatais empty or shorter thanlimit.
Pagination Loop Example (bash + jq)
Section titled “Pagination Loop Example (bash + jq)”CURSOR=""while :; do URL="https://messaging.mahadata.io/v1/campaign-runs/$RUN_ID/recipients?status=failed&limit=500" if [ -n "$CURSOR" ]; then URL="${URL}&after=${CURSOR}" fi
RESP=$(curl -sS "$URL" -H "Authorization: Bearer $API_KEY") echo "$RESP" | jq -c '.data[]'
NEXT=$(echo "$RESP" | jq -r '.next_cursor // empty') if [ -z "$NEXT" ]; then break fi CURSOR="$NEXT"donemessage_id Visibility Policy & Customer PII Masking
Section titled “message_id Visibility Policy & Customer PII Masking”message_idVisibility: Themessage_idfield contains the channel provider’s message identifier (such as the WhatsAppwamid). It respects your account’s provider message ID visibility policy (the same account setting that governs the other messaging APIs and portal exports). For accounts where provider message IDs are hidden, or for rows not yet sent (pending) or failed prior to provider submission,message_idisnull. When customer PII masking is enabled,message_idis alwaysnullbecause a WhatsApp message id embeds the recipient number.- Phone Number Masking (PII Masking): When customer PII masking is enabled for your account, the
phonefield in/recipientsresponses is automatically masked (for example,+62812•••••890). Recipient pagination cursors (next_cursor) are opaque random tokens stored server-side, so raw phone numbers are never exposed in cursor strings.
HTTP Error Reference
Section titled “HTTP Error Reference”| HTTP Status | Cause & Resolution |
|---|---|
400 Bad Request | Malformed after cursor, expired (> 1 hour) or mismatched recipient cursor token, or an unsupported status filter value (allowed: pending, sent, delivered, read, failed, replied). |
401 Unauthorized | Missing Authorization: Bearer <API_KEY> header, invalid token format, or inactive/expired API key. |
403 Forbidden | The requested campaign_id or run_id exists but belongs to another account. |
404 Not Found | The requested campaign_id or run_id does not exist. |
429 Too Many Requests | Exceeded the 60 requests/minute limit for this API key. Wait before retrying. |