{
  "info": {
    "name": "BestSMS.lk API",
    "_postman_id": "6f7d2b1e-b357-4a5d-a001-0b35a7514c01",
    "description": "All BestSMS.lk API v1 endpoints. Set the api_key and sender_id collection variables, then run Send SMS first: it stores campaign_id and message_id for the other requests. Docs: https://bestsms.lk/sdk",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{api_key}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://bestsms.lk/api/v1"
    },
    {
      "key": "api_key",
      "value": "bsk_live_your_key_here"
    },
    {
      "key": "sender_id",
      "value": "MYSHOP"
    },
    {
      "key": "campaign_id",
      "value": "1"
    },
    {
      "key": "message_id",
      "value": "1"
    },
    {
      "key": "otp_id",
      "value": ""
    },
    {
      "key": "giveaway_slug",
      "value": "xmas-hamper"
    }
  ],
  "item": [
    {
      "name": "Account",
      "item": [
        {
          "name": "API info",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/",
              "host": [
                "{{base_url}}"
              ],
              "path": []
            },
            "description": "Name and version of the API. No key needed.",
            "auth": {
              "type": "noauth"
            }
          }
        },
        {
          "name": "Check your balance",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/balance",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "balance"
              ]
            },
            "description": "Remaining credits and the price per SMS on your account."
          }
        }
      ]
    },
    {
      "name": "SMS",
      "item": [
        {
          "name": "Send SMS",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/send",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                "send"
              ]
            },
            "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.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": \"0771234567,0762289014\",\n  \"sender_id\": \"{{sender_id}}\",\n  \"message\": \"Your order #2041 is ready for pickup.\",\n  \"client_ref\": \"order-2041\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "if (j.campaign_id) pm.collectionVariables.set('campaign_id', j.campaign_id);",
                  "if (j.messages && j.messages.length) pm.collectionVariables.set('message_id', j.messages[0].id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Send with a simple link",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/send?api_key={{api_key}}&to=0771234567&sender_id={{sender_id}}&message=Your bill is Rs 2,450. Thank you!",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "send"
              ],
              "query": [
                {
                  "key": "api_key",
                  "value": "{{api_key}}"
                },
                {
                  "key": "to",
                  "value": "0771234567"
                },
                {
                  "key": "sender_id",
                  "value": "{{sender_id}}"
                },
                {
                  "key": "message",
                  "value": "Your bill is Rs 2,450. Thank you!"
                }
              ]
            },
            "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.",
            "auth": {
              "type": "noauth"
            }
          }
        },
        {
          "name": "Get a message status",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sms/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sms",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{message_id}}"
                }
              ]
            },
            "description": "Status is queued, sent, delivered, failed or cancelled. Encoding is gsm or unicode."
          }
        }
      ]
    },
    {
      "name": "Campaigns",
      "item": [
        {
          "name": "List campaigns",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/campaigns?page=1",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "campaigns"
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                }
              ]
            },
            "description": "Newest first, 50 per page."
          }
        },
        {
          "name": "Get one campaign",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/campaigns/:id",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "campaigns",
                ":id"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{campaign_id}}"
                }
              ]
            },
            "description": "One campaign with its counters."
          }
        },
        {
          "name": "Cancel a campaign",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/campaigns/:id/cancel",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "campaigns",
                ":id",
                "cancel"
              ],
              "variable": [
                {
                  "key": "id",
                  "value": "{{campaign_id}}"
                }
              ]
            },
            "description": "Stops a scheduled or sending campaign and refunds credits for messages not yet sent.",
            "body": {
              "mode": "raw",
              "raw": "{}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "Sender IDs",
      "item": [
        {
          "name": "List sender IDs",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sender-ids",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sender-ids"
              ]
            },
            "description": "Your sender IDs and their status. Only approved ones can send."
          }
        },
        {
          "name": "Request a sender ID",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/sender-ids",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "sender-ids"
              ]
            },
            "description": "3 to 11 characters: letters, digits, spaces, dots, & or -, with at least one letter. Up to 5 pending requests.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"sender_id\": \"MYSHOP\",\n  \"business_name\": \"My Shop (Pvt) Ltd\",\n  \"purpose\": \"Order updates and offers for our customers\",\n  \"sample_message\": \"Your order #2041 is ready for pickup.\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "OTP",
      "item": [
        {
          "name": "Send an OTP code",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/otp/send",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "otp",
                "send"
              ]
            },
            "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.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": \"0771234567\",\n  \"sender_id\": \"{{sender_id}}\",\n  \"length\": 6,\n  \"expiry\": 300,\n  \"message\": \"Your MyShop login code is {code}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "const j = pm.response.json();",
                  "if (j.otp_id) pm.collectionVariables.set('otp_id', j.otp_id);"
                ]
              }
            }
          ]
        },
        {
          "name": "Verify an OTP code",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/otp/verify",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "otp",
                "verify"
              ]
            },
            "description": "A code works once. After 5 wrong tries it locks with otp_too_many_attempts.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"to\": \"0771234567\",\n  \"code\": \"482916\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "Contacts",
      "item": [
        {
          "name": "List contact groups",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/groups",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "groups"
              ]
            },
            "description": "Your contact groups with the number of contacts in each."
          }
        },
        {
          "name": "Add a contact",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/contacts",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "contacts"
              ]
            },
            "description": "Adds or updates a number in a group. Pass group (a name) to create the group if missing.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"group\": \"Loyalty members\",\n  \"phone\": \"0771234567\",\n  \"name\": \"Nimal\",\n  \"field1\": \"1,250 points\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        },
        {
          "name": "Add an opt-out",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              },
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/optouts",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "optouts"
              ]
            },
            "description": "Numbers on your opt-out list are skipped in every campaign. OTP messages still go through.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"phone\": \"0771234567\",\n  \"reason\": \"Replied STOP\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            }
          }
        }
      ]
    },
    {
      "name": "Giveaways",
      "item": [
        {
          "name": "List giveaways",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/giveaways",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "giveaways"
              ]
            },
            "description": "Your giveaways with their public link and entry count."
          }
        },
        {
          "name": "List giveaway entries",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Accept",
                "value": "application/json"
              }
            ],
            "url": {
              "raw": "{{base_url}}/giveaways/:slug/entries?page=1",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "giveaways",
                ":slug",
                "entries"
              ],
              "variable": [
                {
                  "key": "slug",
                  "value": "{{giveaway_slug}}"
                }
              ],
              "query": [
                {
                  "key": "page",
                  "value": "1"
                }
              ]
            },
            "description": "Entries for one giveaway, oldest first, 100 per page."
          }
        }
      ]
    }
  ]
}
