Chilkat Online Tools

unicodeC / Plivo REST API / Send SMS/MMS using powerpack

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    CkHttpW_putBasicAuth(http,TRUE);
    CkHttpW_putLogin(http,L"{{auth_id}}");
    CkHttpW_putPassword(http,L"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.

    // {
    //   "powerpack_uuid": "your_powerpack_uuid",
    //   "dst": "14152223333",
    //   "text": "Hello, this is a sample text",
    //   "type": "mms",
    //   "media_urls": "https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif",
    //   "url": "http://foo.com/sms_status/",
    //   "method": "POST",
    //   "log": "true",
    //   "trackable": "false"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"powerpack_uuid",L"your_powerpack_uuid");
    CkJsonObjectW_UpdateString(json,L"dst",L"14152223333");
    CkJsonObjectW_UpdateString(json,L"text",L"Hello, this is a sample text");
    CkJsonObjectW_UpdateString(json,L"type",L"mms");
    CkJsonObjectW_UpdateString(json,L"media_urls",L"https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif");
    CkJsonObjectW_UpdateString(json,L"url",L"http://foo.com/sms_status/");
    CkJsonObjectW_UpdateString(json,L"method",L"POST");
    CkJsonObjectW_UpdateString(json,L"log",L"true");
    CkJsonObjectW_UpdateString(json,L"trackable",L"false");

    resp = CkHttpW_PostJson3(http,L"https://api.plivo.com/v1/Account/<auth_id>/Message/",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

Curl Command

curl -X POST
	-u '{{auth_id}}:password'
	-d '{
    "powerpack_uuid": "your_powerpack_uuid",
    "dst": "14152223333",
    "text": "Hello, this is a sample text",
    "type": "mms",
    "media_urls": "https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif",
    "url": "http://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/MMS using powerpack",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"powerpack_uuid\": \"your_powerpack_uuid\",\n    \"dst\": \"14152223333\",\n    \"text\": \"Hello, this is a sample text\",\n    \"type\": \"mms\",\n    \"media_urls\": \"https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif\",\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",
        ""
      ]
    },
    "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/MMS using powerpack",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"powerpack_uuid\": \"your_powerpack_uuid\",\n    \"dst\": \"14152223333\",\n    \"text\": \"Hello, this is a sample text\",\n    \"type\": \"mms\", // change the type as per your requirement\n    \"media_urls\": \"https://media.giphy.com/media/26gscSULUcfKU7dHq/source.gif\", // omit this, if the \"type\" is \"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",
            ""
          ]
        }
      },
      "_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}"
    }
  ]
}