Chilkat Online Tools

SQL Server / Plivo REST API / Create an Application

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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.

    -- {
    --   "answer_url": "http://answer.url",
    --   "app_name": "Test App",
    --   "answer_method": "POST",
    --   "hangup_url": "http://hangup.url",
    --   "hangup_method": "POST",
    --   "fallback_answer_url": "http://fallback.url",
    --   "fallback_method": "POST",
    --   "message_url": "http://message.url",
    --   "message_method": "POST",
    --   "default_number_app": "true",
    --   "default_endpoint_app": "true",
    --   "subaccount": "SAXXXXXXXXXXX",
    --   "log_incoming_messages": "true"
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'answer_url', 'http://answer.url'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'app_name', 'Test App'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'answer_method', 'POST'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'hangup_url', 'http://hangup.url'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'hangup_method', 'POST'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fallback_answer_url', 'http://fallback.url'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'fallback_method', 'POST'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'message_url', 'http://message.url'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'message_method', 'POST'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'default_number_app', 'true'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'default_endpoint_app', 'true'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'subaccount', 'SAXXXXXXXXXXX'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'log_incoming_messages', 'true'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.plivo.com/v1/Account/<auth_id>/Application/', '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 '{
    "answer_url": "http://answer.url",
    "app_name": "Test App",
    "answer_method": "POST",
    "hangup_url": "http://hangup.url",
    "hangup_method": "POST",
    "fallback_answer_url": "http://fallback.url",
    "fallback_method": "POST",
    "message_url": "http://message.url",
    "message_method": "POST",
    "default_number_app": "true",
    "default_endpoint_app": "true",
    "subaccount": "SAXXXXXXXXXXX",
    "log_incoming_messages": "true"
}'
https://api.plivo.com/v1/Account/<auth_id>/Application/

Postman Collection Item JSON

{
  "name": "Create an Application",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"answer_url\": \"http://answer.url\",\n    \"app_name\": \"Test App\",\n    \"answer_method\": \"POST\",\n    \"hangup_url\": \"http://hangup.url\",\n    \"hangup_method\": \"POST\",\n    \"fallback_answer_url\": \"http://fallback.url\",\n    \"fallback_method\": \"POST\",\n    \"message_url\": \"http://message.url\",\n    \"message_method\": \"POST\",\n    \"default_number_app\": \"true\",\n    \"default_endpoint_app\": \"true\",\n    \"subaccount\": \"SAXXXXXXXXXXX\",\n    \"log_incoming_messages\": \"true\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Application/",
      "protocol": "https",
      "host": [
        "api",
        "plivo",
        "com"
      ],
      "path": [
        "v1",
        "Account",
        "{{auth_id}}",
        "Application",
        ""
      ]
    },
    "description": "Creates an Application. Creating an application is usually the first step, after which you would attach this application either to a number or an endpoint.\n\nBelow is the list of arguments that can be passed in this API request, more information can be found [here](https://www.plivo.com/docs/account/api/application#create-an-application)\n\n| Arguments   | Description | Required/Conditional/Optional     |\n| :---        |    :----:   |          ---: |\n| answer_url      | The URL Plivo will fetch when a call executes this application. More details. | Required  |\n| app_name   | The name of your application | Required |\n| answer_method   | The method used to call the answer_url. Defaults to POST. | Optional |\n| hangup_url   | The URL that will be notified by Plivo when the call hangs up. Defaults to answer_url. More details. | Optional |\n| hangup_method| The method used to call the hangup_url. Defaults to POST. | Optional |\n| fallback_answer_url| Invoked by Plivo only if answer_url is unavailable or the XML response is invalid. Should contain a XML response. | Optional |\n| fallback_method| The method used to call the fallback_answer_url. Defaults to POST.| Optional |\n| message_url| The URL that will be notified by Plivo when an inbound message is received. Defaults not set.| Optional |\n| message_method| The method used to call the message_url. Defaults to POST.| Optional |\n| default_number_app| If set to true, this parameter ensures that newly created numbers, which don't have an app_id, point to this application.| Optional |\n| default_endpoint_app| If set to true, this parameter ensures that newly created endpoints, which don't have an app_id, point to this application.| Optional |\n| subaccount| ID of the subaccount to which this application needs to be associated with.| Optional |\n| log_incoming_messages| If set to false, the content of incoming messages to Plivo phone numbers associated with this application are not logged in Plivo systems, including the debug logs available on the Plivo console. Additionally, the last three digits of the from number are redacted in all system logs and in the Message Detail Record (MDR) of the incoming message.<br />log_incoming_messages defaults true when not specified.<br />Note that non-redacted content and from number is always passed to the the message_url irrespective of the value set for this flag.| Optional |"
  },
  "response": [
    {
      "name": "Create an Application",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"answer_url\": \"http://answer.url\",\n    \"app_name\": \"Test App\",\n    \"answer_method\": \"POST\",\n    \"hangup_url\": \"http://hangup.url\",\n    \"hangup_method\": \"POST\",\n    \"fallback_answer_url\": \"http://fallback.url\",\n    \"fallback_method\": \"POST\",\n    \"message_url\": \"http://message.url\",\n    \"message_method\": \"POST\",\n    \"default_number_app\": \"true\",\n    \"default_endpoint_app\": \"true\",\n    \"subaccount\": \"SAXXXXXXXXXXX\",\n    \"log_incoming_messages\": \"true\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.plivo.com/v1/Account/{{auth_id}}/Application/",
          "protocol": "https",
          "host": [
            "api",
            "plivo",
            "com"
          ],
          "path": [
            "v1",
            "Account",
            "{{auth_id}}",
            "Application",
            ""
          ]
        }
      },
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
      ],
      "cookie": [
      ],
      "body": "{\n    \"message\": \"created\",\n    \"app_id\": \"15784735442685051\",\n    \"api_id\": \"5a9fcb68-582d-11e1-86da-6ff39efcb949\"\n}"
    }
  ]
}