{
  "info": {
    "_postman_id": "e071fbd9-258e-4a7b-94bc-0ccd46e36b66",
    "name": "MegaSMS API v1",
    "description": "Preconfigured requests for the MegaSMS SMS API. Create an API token in the vendor portal, set api_token, then run the requests.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{"key": "token", "value": "{{api_token}}", "type": "string"}]
  },
  "variable": [
    {"key": "base_url", "value": "https://megasms.co.tz/api/v1", "type": "string"},
    {"key": "api_token", "value": "", "type": "string"},
    {"key": "request_id", "value": "", "type": "string"}
  ],
  "item": [
    {
      "name": "Account",
      "item": [
        {
          "name": "Get SMS balance",
          "request": {
            "method": "GET",
            "header": [{"key": "Accept", "value": "application/json"}],
            "url": {"raw": "{{base_url}}/balance", "host": ["{{base_url}}"], "path": ["balance"]},
            "description": "Returns the vendor SMS-unit balance and rate. Requires balance:read."
          }
        }
      ]
    },
    {
      "name": "Messages",
      "item": [
        {
          "name": "Send SMS",
          "event": [{
            "listen": "test",
            "script": {
              "type": "text/javascript",
              "exec": [
                "if (pm.response.code === 200) {",
                "  const body = pm.response.json();",
                "  if (body.data && body.data.request_id) pm.collectionVariables.set('request_id', body.data.request_id);",
                "}"
              ]
            }
          }],
          "request": {
            "method": "POST",
            "header": [
              {"key": "Content-Type", "value": "application/json"},
              {"key": "Accept", "value": "application/json"}
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": \"255712345678\",\n  \"sender_id\": \"MEGASMS\",\n  \"message\": \"Hello from the MegaSMS API\"\n}",
              "options": {"raw": {"language": "json"}}
            },
            "url": {"raw": "{{base_url}}/messages", "host": ["{{base_url}}"], "path": ["messages"]},
            "description": "Sends an SMS. Replace the example recipient and sender ID before sending. Requires messages:send."
          }
        },
        {
          "name": "Get message request status",
          "request": {
            "method": "GET",
            "header": [{"key": "Accept", "value": "application/json"}],
            "url": {"raw": "{{base_url}}/messages/{{request_id}}", "host": ["{{base_url}}"], "path": ["messages", "{{request_id}}"]},
            "description": "Gets the request and recipient statuses. request_id is automatically saved after a successful Send SMS request. Requires messages:read."
          }
        }
      ]
    }
  ]
}
