{
  "openapi": "3.0.3",
  "info": {
    "title": "BestSMS.lk API",
    "version": "1.0.0",
    "description": "Send SMS and OTP codes to Sri Lankan mobile numbers, track delivery, and manage sender IDs, contacts and giveaways. Every endpoint takes and returns JSON. Errors look like {\"ok\": false, \"error\": {\"code\", \"message\"}}. Each key has a per-minute request limit (X-RateLimit-Limit and X-RateLimit-Remaining headers). Webhooks are signed: X-BestSMS-Signature is sha256= followed by the hex HMAC-SHA256 of the raw body keyed with your signing secret.",
    "contact": {
      "name": "BestSMS.lk",
      "url": "https://bestsms.lk/docs"
    }
  },
  "externalDocs": {
    "description": "SDKs and guides",
    "url": "https://bestsms.lk/sdk"
  },
  "servers": [
    {
      "url": "https://bestsms.lk/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    },
    {
      "apiKeyHeader": []
    }
  ],
  "tags": [
    {
      "name": "Account"
    },
    {
      "name": "SMS"
    },
    {
      "name": "Campaigns"
    },
    {
      "name": "Sender IDs"
    },
    {
      "name": "OTP"
    },
    {
      "name": "Contacts"
    },
    {
      "name": "Giveaways"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "ping",
        "tags": [
          "Account"
        ],
        "summary": "API info",
        "description": "Name and version of the API. No key needed.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ping"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/balance": {
      "get": {
        "operationId": "getBalance",
        "tags": [
          "Account"
        ],
        "summary": "Check your balance",
        "description": "Remaining credits and the price per SMS on your account.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sms/send": {
      "post": {
        "operationId": "sendSms",
        "tags": [
          "SMS"
        ],
        "summary": "Send SMS",
        "description": "Send one message to one or many numbers. Credits are held when the request is accepted and credits for failed numbers are refunded when the campaign finishes. Up to 100 recipients are sent before the response returns; larger lists are queued.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SendRequest"
              },
              "example": {
                "to": "0771234567,0762289014",
                "sender_id": "MYSHOP",
                "message": "Your order #2041 is ready for pickup.",
                "client_ref": "order-2041"
              }
            }
          }
        }
      }
    },
    "/send": {
      "get": {
        "operationId": "sendSimpleLink",
        "tags": [
          "SMS"
        ],
        "summary": "Send with a simple link",
        "description": "For POS systems and devices that can only open a URL. Same response as POST /sms/send. The key can go in the api_key query parameter.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "api_key",
            "in": "query",
            "required": false,
            "description": "Your API key, when you cannot send the Authorization header.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "description": "Numbers separated by commas.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "message",
            "in": "query",
            "required": true,
            "description": "URL-encoded text.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sender_id",
            "in": "query",
            "required": false,
            "description": "An approved sender ID.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          },
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ]
      }
    },
    "/sms/{id}": {
      "get": {
        "operationId": "getMessage",
        "tags": [
          "SMS"
        ],
        "summary": "Get a message status",
        "description": "Status is queued, sent, delivered, failed or cancelled. Encoding is gsm or unicode.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "tags": [
          "Campaigns"
        ],
        "summary": "List campaigns",
        "description": "Newest first, 50 per page.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignList"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, starting at 1.",
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/campaigns/{id}": {
      "get": {
        "operationId": "getCampaign",
        "tags": [
          "Campaigns"
        ],
        "summary": "Get one campaign",
        "description": "One campaign with its counters.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/campaigns/{id}/cancel": {
      "post": {
        "operationId": "cancelCampaign",
        "tags": [
          "Campaigns"
        ],
        "summary": "Cancel a campaign",
        "description": "Stops a scheduled or sending campaign and refunds credits for messages not yet sent.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CancelResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/sender-ids": {
      "get": {
        "operationId": "listSenderIds",
        "tags": [
          "Sender IDs"
        ],
        "summary": "List sender IDs",
        "description": "Your sender IDs and their status. Only approved ones can send.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderIdList"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "requestSenderId",
        "tags": [
          "Sender IDs"
        ],
        "summary": "Request a sender ID",
        "description": "3 to 11 characters: letters, digits, spaces, dots, & or -, with at least one letter. Up to 5 pending requests.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SenderIdRequestResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SenderIdRequest"
              },
              "example": {
                "sender_id": "MYSHOP",
                "business_name": "My Shop (Pvt) Ltd",
                "purpose": "Order updates and offers for our customers",
                "sample_message": "Your order #2041 is ready for pickup."
              }
            }
          }
        }
      }
    },
    "/otp/send": {
      "post": {
        "operationId": "sendOtp",
        "tags": [
          "OTP"
        ],
        "summary": "Send an OTP code",
        "description": "Generates a random code, texts it and stores only a hash. A new code to the same number replaces the old one. 5 codes per number per 10 minutes.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OtpSendResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OtpSendRequest"
              },
              "example": {
                "to": "0771234567",
                "sender_id": "MYSHOP",
                "length": 6,
                "expiry": 300,
                "message": "Your MyShop login code is {code}"
              }
            }
          }
        }
      }
    },
    "/otp/verify": {
      "post": {
        "operationId": "verifyOtp",
        "tags": [
          "OTP"
        ],
        "summary": "Verify an OTP code",
        "description": "A code works once. After 5 wrong tries it locks with otp_too_many_attempts.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OtpVerifyResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OtpVerifyRequest"
              },
              "example": {
                "to": "0771234567",
                "code": "482916"
              }
            }
          }
        }
      }
    },
    "/groups": {
      "get": {
        "operationId": "listGroups",
        "tags": [
          "Contacts"
        ],
        "summary": "List contact groups",
        "description": "Your contact groups with the number of contacts in each.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GroupList"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/contacts": {
      "post": {
        "operationId": "addContact",
        "tags": [
          "Contacts"
        ],
        "summary": "Add a contact",
        "description": "Adds or updates a number in a group. Pass group (a name) to create the group if missing.",
        "responses": {
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactResult"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              },
              "example": {
                "group": "Loyalty members",
                "phone": "0771234567",
                "name": "Nimal",
                "field1": "1,250 points"
              }
            }
          }
        }
      }
    },
    "/optouts": {
      "post": {
        "operationId": "addOptOut",
        "tags": [
          "Contacts"
        ],
        "summary": "Add an opt-out",
        "description": "Numbers on your opt-out list are skipped in every campaign. OTP messages still go through.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OptOutRequest"
              },
              "example": {
                "phone": "0771234567",
                "reason": "Replied STOP"
              }
            }
          }
        }
      }
    },
    "/giveaways": {
      "get": {
        "operationId": "listGiveaways",
        "tags": [
          "Giveaways"
        ],
        "summary": "List giveaways",
        "description": "Your giveaways with their public link and entry count.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GiveawayList"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/giveaways/{slug}/entries": {
      "get": {
        "operationId": "listGiveawayEntries",
        "tags": [
          "Giveaways"
        ],
        "summary": "List giveaway entries",
        "description": "Entries for one giveaway, oldest first, 100 per page.",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GiveawayEntries"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized: the key is missing, wrong or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "unauthorized (suspended account) or forbidden_ip",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found, or otp_invalid when no code was sent to the number",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid_request, sender_not_approved, otp_invalid or otp_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited or otp_too_many_attempts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "server_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, starting at 1.",
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer bsk_live_..."
      },
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "apiKeyQuery": {
        "type": "apiKey",
        "in": "query",
        "name": "api_key",
        "description": "Only for the simple GET /send link."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "ok",
          "error"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthorized",
                  "forbidden_ip",
                  "rate_limited",
                  "invalid_request",
                  "sender_not_approved",
                  "insufficient_credits",
                  "not_found",
                  "otp_invalid",
                  "otp_expired",
                  "otp_too_many_attempts",
                  "server_error"
                ]
              },
              "message": {
                "type": "string"
              },
              "attempts_left": {
                "type": "integer",
                "description": "Only for otp_invalid."
              }
            }
          }
        }
      },
      "Ok": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          }
        }
      },
      "Ping": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "docs": {
            "type": "string"
          }
        }
      },
      "Balance": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "credits": {
            "type": "number"
          },
          "price_per_sms": {
            "type": "number"
          },
          "currency": {
            "type": "string",
            "example": "LKR"
          }
        }
      },
      "Recipient": {
        "type": "object",
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "field1": {
            "type": "string"
          },
          "field2": {
            "type": "string"
          },
          "client_ref": {
            "type": "string",
            "maxLength": 120
          }
        }
      },
      "SendRequest": {
        "type": "object",
        "required": [
          "to",
          "message"
        ],
        "properties": {
          "to": {
            "oneOf": [
              {
                "type": "string",
                "description": "Numbers separated by commas, spaces or semicolons."
              },
              {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "$ref": "#/components/schemas/Recipient"
                    }
                  ]
                }
              }
            ]
          },
          "message": {
            "type": "string",
            "maxLength": 1530,
            "description": "{name}, {phone}, {field1}, {field2} are filled per recipient."
          },
          "sender_id": {
            "type": "string",
            "description": "Approved sender ID. Default: your first approved one. Also accepted as sender or mask."
          },
          "schedule_at": {
            "type": "string",
            "example": "2026-12-01 09:30",
            "description": "Sri Lanka time. Times less than a minute away send now."
          },
          "name": {
            "type": "string",
            "description": "Campaign name for your dashboard."
          },
          "client_ref": {
            "type": "string",
            "maxLength": 120,
            "description": "Copied onto every message that has no client_ref of its own."
          }
        }
      },
      "SentMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "phone": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "client_ref": {
            "type": "string"
          }
        }
      },
      "SendResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "campaign_id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "queued",
              "sending",
              "done",
              "failed",
              "cancelled"
            ]
          },
          "recipients": {
            "type": "integer"
          },
          "credits_reserved": {
            "type": "number"
          },
          "invalid": {
            "type": "integer"
          },
          "opted_out": {
            "type": "integer"
          },
          "scheduled_at": {
            "type": "string",
            "description": "Only when scheduled."
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SentMessage"
            },
            "description": "Only when there are 100 recipients or fewer."
          }
        }
      },
      "Message": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "campaign_id": {
            "type": "integer"
          },
          "phone": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sent",
              "delivered",
              "failed",
              "cancelled"
            ]
          },
          "segments": {
            "type": "integer"
          },
          "encoding": {
            "type": "string",
            "enum": [
              "gsm",
              "unicode"
            ]
          },
          "gateway_ref": {
            "type": "string",
            "nullable": true
          },
          "error": {
            "type": "string",
            "nullable": true
          },
          "client_ref": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string"
          },
          "sent_at": {
            "type": "string",
            "nullable": true
          },
          "delivered_at": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "MessageResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "message": {
            "$ref": "#/components/schemas/Message"
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "sender": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "sent": {
            "type": "integer"
          },
          "delivered": {
            "type": "integer"
          },
          "failed": {
            "type": "integer"
          },
          "credits_used": {
            "oneOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "description": "Decimal; may arrive as a string such as \"2.00\"."
          },
          "credits_reserved": {
            "oneOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "description": "Decimal; may arrive as a string such as \"2.00\"."
          },
          "scheduled_at": {
            "type": "string",
            "nullable": true
          },
          "started_at": {
            "type": "string",
            "nullable": true
          },
          "finished_at": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string"
          }
        }
      },
      "CampaignList": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "campaigns": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Campaign"
            }
          },
          "page": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          }
        }
      },
      "CampaignResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "campaign": {
            "$ref": "#/components/schemas/Campaign"
          }
        }
      },
      "CancelResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "refunded": {
            "type": "number"
          }
        }
      },
      "SenderId": {
        "type": "object",
        "properties": {
          "sender_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected",
              "revoked"
            ]
          },
          "is_default": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "nullable": true
          },
          "shared": {
            "type": "boolean"
          }
        }
      },
      "SenderIdList": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "sender_ids": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SenderId"
            }
          }
        }
      },
      "SenderIdRequest": {
        "type": "object",
        "required": [
          "sender_id",
          "purpose"
        ],
        "properties": {
          "sender_id": {
            "type": "string",
            "minLength": 3,
            "maxLength": 11,
            "pattern": "^(?=.*[A-Za-z])[A-Za-z0-9 .&\\-]{3,11}$"
          },
          "business_name": {
            "type": "string",
            "description": "Defaults to the company on your account."
          },
          "purpose": {
            "type": "string",
            "minLength": 10
          },
          "sample_message": {
            "type": "string"
          }
        }
      },
      "SenderIdRequestResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "id": {
            "type": "integer"
          },
          "sender_id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "OtpSendRequest": {
        "type": "object",
        "required": [
          "to"
        ],
        "properties": {
          "to": {
            "type": "string",
            "description": "One Sri Lankan mobile number. Also accepted as phone."
          },
          "sender_id": {
            "type": "string"
          },
          "length": {
            "type": "integer",
            "minimum": 4,
            "maximum": 8,
            "default": 6
          },
          "expiry": {
            "type": "integer",
            "minimum": 60,
            "maximum": 1800,
            "default": 300
          },
          "message": {
            "type": "string",
            "default": "Your verification code is {code}",
            "description": "Must contain {code}."
          }
        }
      },
      "OtpSendResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "otp_id": {
            "type": "integer"
          },
          "message_id": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OtpVerifyRequest": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "otp_id": {
            "type": "integer"
          }
        },
        "description": "Send to or otp_id."
      },
      "OtpVerifyResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "verified": {
            "type": "boolean"
          },
          "phone": {
            "type": "string"
          }
        }
      },
      "Group": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "contacts": {
            "type": "integer"
          }
        }
      },
      "GroupList": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Group"
            }
          }
        }
      },
      "ContactRequest": {
        "type": "object",
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "group_id": {
            "type": "integer"
          },
          "group": {
            "type": "string",
            "description": "Group name, created if missing. Default \"API contacts\"."
          },
          "name": {
            "type": "string"
          },
          "field1": {
            "type": "string"
          },
          "field2": {
            "type": "string"
          }
        }
      },
      "ContactResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "contact_id": {
            "type": "integer"
          },
          "group_id": {
            "type": "integer"
          }
        }
      },
      "OptOutRequest": {
        "type": "object",
        "required": [
          "phone"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "Giveaway": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "entries": {
            "type": "integer"
          },
          "starts_at": {
            "type": "string",
            "nullable": true
          },
          "ends_at": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string"
          },
          "link": {
            "type": "string",
            "description": "Public giveaway page on the giveaway's chosen domain."
          }
        }
      },
      "GiveawayList": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "giveaways": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Giveaway"
            }
          }
        }
      },
      "GiveawayEntry": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "nullable": true
          },
          "verified": {
            "type": "boolean"
          },
          "referrals": {
            "type": "integer"
          },
          "bonus_entries": {
            "type": "integer"
          },
          "entries": {
            "type": "integer",
            "description": "The entrant's total entries, including bonus entries from social actions and referrals."
          },
          "status": {
            "type": "string"
          },
          "answers": {
            "type": "object",
            "nullable": true
          },
          "created_at": {
            "type": "string"
          }
        }
      },
      "GiveawayEntries": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GiveawayEntry"
            }
          },
          "page": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "campaign.finished",
              "message.delivered",
              "message.failed",
              "balance.low",
              "giveaway.entry",
              "webhook.test"
            ]
          },
          "time": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object"
          }
        }
      }
    }
  }
}
