Chilkat Online Tools

SQL Server / Plivo REST API / Send SMS

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', '{{auth_id}}'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "src": "+14152225555",
    --   "dst": "+14152345678",
    --   "text": "Hello, this is a sample text",
    --   "type": "sms",
    --   "url": "https://foo.com/sms status",
    --   "method": "POST",
    --   "log": "true",
    --   "trackable": false
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'src', '+14152225555'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'dst', '+14152345678'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'text', 'Hello, this is a sample text'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'type', 'sms'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'url', 'https://foo.com/sms status'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'method', 'POST'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'log', 'true'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'trackable', 0

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.plivo.com/v1/Account/<auth_id>/Message/', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-u '{{auth_id}}:password'
	-d '{
    "src": "+14152225555",
    "dst": "+14152345678",
    "text": "Hello, this is a sample text",
    "type": "sms",
    "url": "https://foo.com/sms status",
    "method": "POST",
    "log": "true",
    "trackable": false
}'
https://api.plivo.com/v1/Account/<auth_id>/Message/

Postman Collection Item JSON

{
  "name": "Send SMS",
  "request": {
    "auth": {
      "type": "basic",
      "basic": [
        {
          "key": "username",
          "value": "MAMJRHMWU3MJA4YMU5NJ",
          "type": "string"
        },
        {
          "key": "password",
          "value": "ODYwZmMyNGMwZTJlYjE3Y2E0MWY4ZWJiMTVhZDY0",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"src\": \"+14152225555\",\n    \"dst\": \"+14152345678\",\n    \"text\": \"Hello, this is a sample text\",\n    \"type\": \"sms\",\n    \"url\": \"https://foo.com/sms status\",\n    \"method\": \"POST\",\n    \"log\": \"true\",\n    \"trackable\": false\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Message/",
      "protocol": "https",
      "host": [
        "api",
        "plivo",
        "com"
      ],
      "path": [
        "v1",
        "Account",
        "{{auth_id}}",
        "Message",
        ""
      ]
    },
    "description": "Send Message or MMS, below is the list of arguments that can be passed in this API request, more information can be found [here](https://www.plivo.com/docs/sms/api/message#send-a-message)\n\n| Arguments   | Description | Required/Conditional/Optional     |\n| :---        |    :----:   |          ---: |\n| src      | Set this parameter to the sender ID you wish to use. This could a phone number, shortcode or alphanumeric string.| Conditional  |\n| dst   | Set this parameter to the phone number to which the message is to be delivered.        | Required      |\n| text   | Set this parameter to the content of the text message. | Required |\n| type   | Set this parameter either as \"sms\" for SMS messages or as \"mms\" for MMS messages. Defaults to sms.        | Optional      |\n| media_urls   | A comma separated list of URL encoded hyperlinks to the images or gifs to be included in the MMS message. This is a required field if the message type is mms.        | Conditional      |\n| url   | Set this parameter to the fully qualified URL to which status update callbacks for the message should be sent | Optional      |\n| method   | The HTTP method to be used when calling the url defined above. Defaults to POST when not specified. Note that only GET and POST are presently supported.        | Optional      |\n| log   | If set to false, the text and media content of this message will not be logged on Plivo infrastructure, and the dst value will be masked (e.g., +141XXXXX528)        | Optional      |\n| trackable   | Set this parameter to true for messages that have a trackable user action, for example, entering a 2FA verification code. Setting this parameter to true implies that you intend to update Plivo upon successful delivery of the message using the Conversion Feedback API. Read our guide on Providing Conversion Feedback for trackable SMS messages for details. This parameter defaults to false when no specified.       | Optional      |"
  },
  "response": [
    {
      "name": "Send SMS - Success",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"src\": \"14152225555\",\n    \"dst\": \"14152223333\", // for multiple destination use - \"dst\": \"14152223333<\"14152224444\"\n    \"text\": \"Hello, this is a sample text\",\n    \"type\": \"sms\",\n    \"url\": \"http://foo.com/sms_status/\",\n    \"method\": \"POST\",\n    \"log\": \"true\",\n    \"trackable\": \"false\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Message/",
          "protocol": "https",
          "host": [
            "api",
            "plivo",
            "com"
          ],
          "path": [
            "v1",
            "Account",
            "{{auth_id}}",
            "Message",
            ""
          ]
        }
      },
      "code": 202,
      "_postman_previewlanguage": "json",
      "header": [
      ],
      "cookie": [
      ],
      "body": "{\n    \"message\": \"message(s) queued\",\n    \"message_uuid\": [\n        \"db3ce55a-7f1d-11e1-8ea7-1231380bc196\"\n    ],\n    \"api_id\": \"db342550-7f1d-11e1-8ea7-1231380bc196\"\n}"
    }
  ]
}