{
  "info": {
    "name": "ABM SMS Gateway API",
    "description": "SPEC.md §5 /api/v1 - the full tenant-facing REST surface (Phases 2-6). Two auth modes on the same endpoints (SPEC §4) - see the two top-level folders. Set the collection variables (base_url, api_key, api_secret) before running; the seeded dev credential's values are printed by `php spark db:seed DatabaseSeeder`. See docs/api.md for the full narrative documentation this collection accompanies.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "http://localhost:8095/api/v1"
    },
    {
      "key": "api_key",
      "value": "abmsms_live_xxxxxxxxxxxxxxxx"
    },
    {
      "key": "api_secret",
      "value": "your-plaintext-secret-shown-once-at-creation"
    },
    {
      "key": "message_uuid",
      "value": "00000000-0000-4000-8000-000000000000",
      "description": "Set from a Send response's messages[].message_uuid"
    },
    {
      "key": "download_token",
      "value": "00000000-0000-4000-8000-000000000000",
      "description": "Set from the 'queue CSV export' response's download_token"
    }
  ],
  "item": [
    {
      "name": "Bearer Auth (Mode A)",
      "description": "Authorization: Bearer {api_key}.{secret} - SPEC §4 Mode A. Fastest to integrate; combine with HTTPS and an IP whitelist in production. Every /api/v1 endpoint is represented here.",
      "item": [
        {
          "name": "Estimate SMS cost",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/estimate",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "estimate"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"01712345678\", \"01812345678\"],\n  \"message\": \"আপনার বাইকের সার্ভিস ডিউ ২০ আগস্ট।\"\n}"
            },
            "description": "SPEC §5.3 - dry run, no charge. Same payload shape as send."
          }
        },
        {
          "name": "Send SMS (single/multi)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              },
              {
                "key": "Idempotency-Key",
                "value": "{{$guid}}",
                "description": "Optional - a retried request with the same key within 24h replays the original response instead of sending again (SPEC §5.1/§3.4)."
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/send",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "send"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"01712345678\", \"01812345678\"],\n  \"message\": \"আপনার বাইকের সার্ভিস ডিউ ২০ আগস্ট।\",\n  \"sender_id\": null,\n  \"client_reference\": \"SVC-4471\",\n  \"schedule_at\": null\n}"
            },
            "description": "SPEC §5.1 - max 100 recipients, one shared message body. Returns 202 with batch_uuid + per-recipient status immediately; actual sending happens async in the worker (`spark sms:dispatch`)."
          }
        },
        {
          "name": "Send SMS (bulk, personalized)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/bulk",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "bulk"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Eid Offer Aug 2026\",\n  \"sender_id\": \"ABM-BIKE\",\n  \"messages\": [\n    {\"to\": \"01712345678\", \"message\": \"প্রিয় করিম সাহেব, ...\", \"client_reference\": \"C-101\"},\n    {\"to\": \"01812345678\", \"message\": \"প্রিয় রহিম সাহেব, ...\", \"client_reference\": \"C-102\"}\n  ],\n  \"schedule_at\": null,\n  \"allow_partial\": false\n}"
            },
            "description": "SPEC §5.2 - up to 50,000 recipients, personalized. If the balance can't cover the whole batch, the whole batch is rejected unless allow_partial is true."
          }
        },
        {
          "name": "Bulk status lookup",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/status",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "status"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"message_uuids\": [\"00000000-0000-4000-8000-000000000000\"]\n}"
            },
            "description": "SPEC §5.4 - body is either message_uuids or client_references (max 500). This is what CI3 cron jobs should poll instead of hammering GET /sms/{uuid} in a loop."
          }
        },
        {
          "name": "Get message by UUID",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/{{message_uuid}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "{{message_uuid}}"
              ]
            },
            "description": "SPEC §5.4 - single message full detail. Set the message_uuid collection variable first (e.g. from a Send response)."
          }
        },
        {
          "name": "Reports: message list",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/reports/messages?from=2026-08-01&to=2026-08-31&status=delivered&page=1&per_page=50",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "reports",
                "messages"
              ],
              "query": [
                {
                  "key": "from",
                  "value": "2026-08-01"
                },
                {
                  "key": "to",
                  "value": "2026-08-31"
                },
                {
                  "key": "status",
                  "value": "delivered"
                },
                {
                  "key": "page",
                  "value": "1"
                },
                {
                  "key": "per_page",
                  "value": "50"
                }
              ]
            },
            "description": "SPEC §5.4 - paginated, max per_page 500. All query params are optional filters."
          }
        },
        {
          "name": "Reports: summary",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/reports/summary?from=2026-08-01&to=2026-08-31&group_by=day",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "reports",
                "summary"
              ],
              "query": [
                {
                  "key": "from",
                  "value": "2026-08-01"
                },
                {
                  "key": "to",
                  "value": "2026-08-31"
                },
                {
                  "key": "group_by",
                  "value": "day"
                }
              ]
            },
            "description": "SPEC §5.4 - group_by is day|sender_id|status. Served from the pre-aggregated sms_daily_stats table, so this stays fast regardless of how many messages sms_messages holds."
          }
        },
        {
          "name": "Reports: queue CSV export",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/reports/export?from=2026-08-01&to=2026-08-31&format=csv",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "reports",
                "export"
              ],
              "query": [
                {
                  "key": "from",
                  "value": "2026-08-01"
                },
                {
                  "key": "to",
                  "value": "2026-08-31"
                },
                {
                  "key": "format",
                  "value": "csv"
                }
              ]
            },
            "description": "SPEC §5.4 - queues an async export job and returns a download_token immediately (202-shaped 200 - never streams rows synchronously). Poll the status endpoint below with that token, then download once status is 'completed'."
          }
        },
        {
          "name": "Reports: export status",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/reports/export/{{download_token}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "reports",
                "export",
                "{{download_token}}"
              ]
            },
            "description": "Set download_token from the 'queue CSV export' response. Returns a download_url once status is 'completed'."
          }
        },
        {
          "name": "Reports: download export",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/reports/export/{{download_token}}/download",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "reports",
                "export",
                "{{download_token}}",
                "download"
              ]
            },
            "description": "Streams the generated CSV file once the export job has completed."
          }
        },
        {
          "name": "Get account balance",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/account/balance",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "account",
                "balance"
              ]
            }
          }
        },
        {
          "name": "Get account ledger",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/account/ledger?from=2026-08-01&to=2026-08-31",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "account",
                "ledger"
              ],
              "query": [
                {
                  "key": "from",
                  "value": "2026-08-01"
                },
                {
                  "key": "to",
                  "value": "2026-08-31"
                }
              ]
            },
            "description": "SPEC §5.4 - paginated ledger entries (topup/reserve/charge/refund/adjustment/reversal)."
          }
        },
        {
          "name": "List sender IDs",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sender-ids",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sender-ids"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "HMAC Auth (Mode B)",
      "description": "X-Api-Key / X-Timestamp / X-Nonce / X-Signature - SPEC §4 Mode B. Signature = hex hmac_sha256(secret, \"{method}\\n{path}\\n{timestamp}\\n{nonce}\\n{sha256(raw_body)}\"). A folder-level pre-request script computes these headers automatically on every item below - nothing to fill in by hand beyond api_key/api_secret. A representative subset of endpoints, not a full duplicate of the Bearer folder - every endpoint accepts either mode identically.",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// SPEC §4 Mode B: computes X-Api-Key/X-Timestamp/X-Nonce/X-Signature for",
              "// every request in this folder - nothing to fill in by hand beyond the",
              "// api_key/api_secret collection variables.",
              "const CryptoJS = require('crypto-js');",
              "const apiKey = pm.collectionVariables.get('api_key');",
              "const apiSecret = pm.collectionVariables.get('api_secret');",
              "const timestamp = Math.floor(Date.now() / 1000).toString();",
              "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
              "const method = pm.request.method.toUpperCase();",
              "const path = '/' + pm.request.url.getPath().replace(/^\\/+/, '');",
              "const rawBody = (pm.request.body && pm.request.body.raw) ? pm.request.body.raw : '';",
              "const bodyHash = CryptoJS.SHA256(rawBody).toString();",
              "const baseString = method + '\\n' + path + '\\n' + timestamp + '\\n' + nonce + '\\n' + bodyHash;",
              "const signature = CryptoJS.HmacSHA256(baseString, apiSecret).toString();",
              "pm.request.headers.upsert({ key: 'X-Api-Key', value: apiKey });",
              "pm.request.headers.upsert({ key: 'X-Timestamp', value: timestamp });",
              "pm.request.headers.upsert({ key: 'X-Nonce', value: nonce });",
              "pm.request.headers.upsert({ key: 'X-Signature', value: signature });"
            ]
          }
        }
      ],
      "item": [
        {
          "name": "Estimate SMS cost (HMAC)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/estimate",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "estimate"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"01712345678\"],\n  \"message\": \"Your bike service is due tomorrow.\"\n}"
            }
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// SPEC §4 Mode B: computes X-Api-Key/X-Timestamp/X-Nonce/X-Signature for",
                  "// every request in this folder - nothing to fill in by hand beyond the",
                  "// api_key/api_secret collection variables.",
                  "const CryptoJS = require('crypto-js');",
                  "const apiKey = pm.collectionVariables.get('api_key');",
                  "const apiSecret = pm.collectionVariables.get('api_secret');",
                  "const timestamp = Math.floor(Date.now() / 1000).toString();",
                  "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
                  "const method = pm.request.method.toUpperCase();",
                  "const path = '/' + pm.request.url.getPath().replace(/^\\/+/, '');",
                  "const rawBody = (pm.request.body && pm.request.body.raw) ? pm.request.body.raw : '';",
                  "const bodyHash = CryptoJS.SHA256(rawBody).toString();",
                  "const baseString = method + '\\n' + path + '\\n' + timestamp + '\\n' + nonce + '\\n' + bodyHash;",
                  "const signature = CryptoJS.HmacSHA256(baseString, apiSecret).toString();",
                  "pm.request.headers.upsert({ key: 'X-Api-Key', value: apiKey });",
                  "pm.request.headers.upsert({ key: 'X-Timestamp', value: timestamp });",
                  "pm.request.headers.upsert({ key: 'X-Nonce', value: nonce });",
                  "pm.request.headers.upsert({ key: 'X-Signature', value: signature });"
                ]
              }
            }
          ]
        },
        {
          "name": "Send SMS (HMAC)",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/send",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "send"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"01712345678\"],\n  \"message\": \"Your bike service is due tomorrow.\",\n  \"client_reference\": \"SVC-4472\"\n}"
            }
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// SPEC §4 Mode B: computes X-Api-Key/X-Timestamp/X-Nonce/X-Signature for",
                  "// every request in this folder - nothing to fill in by hand beyond the",
                  "// api_key/api_secret collection variables.",
                  "const CryptoJS = require('crypto-js');",
                  "const apiKey = pm.collectionVariables.get('api_key');",
                  "const apiSecret = pm.collectionVariables.get('api_secret');",
                  "const timestamp = Math.floor(Date.now() / 1000).toString();",
                  "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
                  "const method = pm.request.method.toUpperCase();",
                  "const path = '/' + pm.request.url.getPath().replace(/^\\/+/, '');",
                  "const rawBody = (pm.request.body && pm.request.body.raw) ? pm.request.body.raw : '';",
                  "const bodyHash = CryptoJS.SHA256(rawBody).toString();",
                  "const baseString = method + '\\n' + path + '\\n' + timestamp + '\\n' + nonce + '\\n' + bodyHash;",
                  "const signature = CryptoJS.HmacSHA256(baseString, apiSecret).toString();",
                  "pm.request.headers.upsert({ key: 'X-Api-Key', value: apiKey });",
                  "pm.request.headers.upsert({ key: 'X-Timestamp', value: timestamp });",
                  "pm.request.headers.upsert({ key: 'X-Nonce', value: nonce });",
                  "pm.request.headers.upsert({ key: 'X-Signature', value: signature });"
                ]
              }
            }
          ]
        },
        {
          "name": "Get account balance (HMAC)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/account/balance",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "account",
                "balance"
              ]
            }
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// SPEC §4 Mode B: computes X-Api-Key/X-Timestamp/X-Nonce/X-Signature for",
                  "// every request in this folder - nothing to fill in by hand beyond the",
                  "// api_key/api_secret collection variables.",
                  "const CryptoJS = require('crypto-js');",
                  "const apiKey = pm.collectionVariables.get('api_key');",
                  "const apiSecret = pm.collectionVariables.get('api_secret');",
                  "const timestamp = Math.floor(Date.now() / 1000).toString();",
                  "const nonce = CryptoJS.lib.WordArray.random(16).toString();",
                  "const method = pm.request.method.toUpperCase();",
                  "const path = '/' + pm.request.url.getPath().replace(/^\\/+/, '');",
                  "const rawBody = (pm.request.body && pm.request.body.raw) ? pm.request.body.raw : '';",
                  "const bodyHash = CryptoJS.SHA256(rawBody).toString();",
                  "const baseString = method + '\\n' + path + '\\n' + timestamp + '\\n' + nonce + '\\n' + bodyHash;",
                  "const signature = CryptoJS.HmacSHA256(baseString, apiSecret).toString();",
                  "pm.request.headers.upsert({ key: 'X-Api-Key', value: apiKey });",
                  "pm.request.headers.upsert({ key: 'X-Timestamp', value: timestamp });",
                  "pm.request.headers.upsert({ key: 'X-Nonce', value: nonce });",
                  "pm.request.headers.upsert({ key: 'X-Signature', value: signature });"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Error examples",
      "description": "Requests deliberately built to fail, so you can see the SPEC §5 error envelope shape for each case.",
      "item": [
        {
          "name": "Missing credentials -> 401 AUTH_REQUIRED",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/account/balance",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "account",
                "balance"
              ]
            }
          }
        },
        {
          "name": "Invalid phone number -> 400 INVALID_NUMBER",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/estimate",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "estimate"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"not-a-number\"],\n  \"message\": \"Hello\"\n}"
            }
          }
        },
        {
          "name": "Insufficient balance -> 402 INSUFFICIENT_BALANCE",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/send",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "send"
              ]
            },
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": [\"01712345678\"],\n  \"message\": \"This will fail if your balance cannot cover even one message.\"\n}"
            },
            "description": "Deliberately illustrative - the actual response depends on your test tenant's current balance."
          }
        },
        {
          "name": "Cross-tenant / nonexistent message -> 404 NOT_FOUND",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Authorization",
                "value": "Bearer {{api_key}}.{{api_secret}}"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/00000000-0000-4000-8000-000000000000",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "00000000-0000-4000-8000-000000000000"
              ]
            }
          }
        }
      ]
    }
  ]
}
