Chilkat Online Tools

SQL Server / Plivo REST API / Run a PHLO

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.

    -- {
    --   "auth_id": 123,
    --   "Phlo_id": "c8934b39-2bf1-4d3e-ae9d-c80c780f0482"
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'auth_id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'Phlo_id', 'c8934b39-2bf1-4d3e-ae9d-c80c780f0482'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://phlorunner.plivo.com/v1/account/<auth_id>/phlo/bf0b9d53-edc1-4120-a5fd-620d1f91c425', '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 '{
    "auth_id": {{auth_id}},
    "Phlo_id": "c8934b39-2bf1-4d3e-ae9d-c80c780f0482"
}'
https://phlorunner.plivo.com/v1/account/<auth_id>/phlo/bf0b9d53-edc1-4120-a5fd-620d1f91c425

Postman Collection Item JSON

{
  "name": "Run a PHLO",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"auth_id\": {{auth_id}},\n    \"Phlo_id\": \"c8934b39-2bf1-4d3e-ae9d-c80c780f0482\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://phlorunner.plivo.com/v1/account/{{auth_id}}/phlo/bf0b9d53-edc1-4120-a5fd-620d1f91c425",
      "protocol": "https",
      "host": [
        "phlorunner",
        "plivo",
        "com"
      ],
      "path": [
        "v1",
        "account",
        "{{auth_id}}",
        "phlo",
        "bf0b9d53-edc1-4120-a5fd-620d1f91c425"
      ]
    },
    "description": "Run a PHLO by triggering it via an API request to the PHLO URL. More information can be found [here](https://www.plivo.com/docs/phlo/api/phlo#run-a-phlo)"
  },
  "response": [
    {
      "name": "Run a PHLO",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"auth_id\": \"MAXXXXXXXXX\", // Your Plivo AUTH ID can be found when you log into the Console\n    \"Phlo_id\": \"c8934b39-2bf1-xxxxx-xxxxx-xxxxxxxxx\" //Unique identifier for the PHLO. PHLO ID is available Console->PHLO\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://phlorunner.plivo.com/v1/account/{{auth_id}}/phlo/{phlo_id}",
          "protocol": "https",
          "host": [
            "phlorunner",
            "plivo",
            "com"
          ],
          "path": [
            "v1",
            "account",
            "{{auth_id}}",
            "phlo",
            "{phlo_id}"
          ]
        }
      },
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
      ],
      "cookie": [
      ],
      "body": "{\n    \"phlo_id\": \"4c1a9f23-7f56-4879-bb80-db856e1e7701\",\n    \"api_id\": \"7b6f8256-07c7-4d9a-bf2a-a2cd0f05d269\",\n    \"message\": \"b'Send SMS' - b'Send SMS_1' with phlo_run_uuid: 7b6f8256-07c7-4d9a-bf2a-a2cd0f05d269 executed with response: {'api_id': '81525812-3c04-11e9-aa1e-06c75f1208d2',\\n 'message': 'message(s) queued',\\n 'message_uuid': ['8152b05a-3c04-11e9-aa1e-06c75f1208d2']}\"\n}"
    }
  ]
}