Chilkat Online Tools

C / Sunshine Conversations API / Create Switchboard Integration

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Id;
    const char *Name;
    const char *IntegrationId;
    const char *IntegrationType;
    BOOL DeliverStandbyEvents;
    const char *NextSwitchboardIntegrationId;
    int MessageHistoryCount;

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

    http = CkHttp_Create();

    CkHttp_putBasicAuth(http,TRUE);
    CkHttp_putLogin(http,"username");
    CkHttp_putPassword(http,"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.

    // {
    //   "name": "bot",
    //   "integrationType": "zd:agentWorkspace",
    //   "deliverStandbyEvents": true,
    //   "nextSwitchboardIntegrationId": "5ef21b86e933b7355c11c606",
    //   "messageHistoryCount": 5
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"name","bot");
    CkJsonObject_UpdateString(json,"integrationType","zd:agentWorkspace");
    CkJsonObject_UpdateBool(json,"deliverStandbyEvents",TRUE);
    CkJsonObject_UpdateString(json,"nextSwitchboardIntegrationId","5ef21b86e933b7355c11c606");
    CkJsonObject_UpdateInt(json,"messageHistoryCount",5);

    CkHttp_SetRequestHeader(http,"Content-Type","application/json");

    resp = CkHttp_PostJson3(http,"https://domain.com/v2/apps/{{appId}}/switchboards/:switchboardId/switchboardIntegrations","application/json",json);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(resp);

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "switchboardIntegration": {
    //     "id": "5ef21b86e933b7355c11c604",
    //     "name": "bot",
    //     "integrationId": "5ef21b86e933b7355c11c605",
    //     "integrationType": "zd:agentWorkspace",
    //     "deliverStandbyEvents": true,
    //     "nextSwitchboardIntegrationId": "5ef21b86e933b7355c11c606",
    //     "messageHistoryCount": 5
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Id = CkJsonObject_stringOf(jResp,"switchboardIntegration.id");
    Name = CkJsonObject_stringOf(jResp,"switchboardIntegration.name");
    IntegrationId = CkJsonObject_stringOf(jResp,"switchboardIntegration.integrationId");
    IntegrationType = CkJsonObject_stringOf(jResp,"switchboardIntegration.integrationType");
    DeliverStandbyEvents = CkJsonObject_BoolOf(jResp,"switchboardIntegration.deliverStandbyEvents");
    NextSwitchboardIntegrationId = CkJsonObject_stringOf(jResp,"switchboardIntegration.nextSwitchboardIntegrationId");
    MessageHistoryCount = CkJsonObject_IntOf(jResp,"switchboardIntegration.messageHistoryCount");


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X POST
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
    "name": "bot",
    "integrationType": "zd:agentWorkspace",
    "deliverStandbyEvents": true,
    "nextSwitchboardIntegrationId": "5ef21b86e933b7355c11c606",
    "messageHistoryCount": 5
}'
https://domain.com/v2/apps/{{appId}}/switchboards/:switchboardId/switchboardIntegrations

Postman Collection Item JSON

{
  "name": "Create Switchboard Integration",
  "_postman_id": "9dc9c6be-a814-4995-8787-f493a5aa11d2",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"bot\",\n    \"integrationType\": \"zd:agentWorkspace\",\n    \"deliverStandbyEvents\": true,\n    \"nextSwitchboardIntegrationId\": \"5ef21b86e933b7355c11c606\",\n    \"messageHistoryCount\": 5\n}"
    },
    "url": {
      "raw": "{{url}}/v2/apps/{{appId}}/switchboards/:switchboardId/switchboardIntegrations",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "switchboards",
        ":switchboardId",
        "switchboardIntegrations"
      ],
      "variable": [
        {
          "key": "switchboardId"
        }
      ]
    },
    "description": "Create a switchboard integration."
  },
  "response": [
    {
      "id": "39839588-4599-4f5d-93a9-03ca6b518509",
      "name": "Only one switchboard per app can be created",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"bot\",\n    \"integrationType\": \"zd:agentWorkspace\",\n    \"deliverStandbyEvents\": true,\n    \"nextSwitchboardIntegrationId\": \"5ef21b86e933b7355c11c606\",\n    \"messageHistoryCount\": 5\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/switchboards/:switchboardId/switchboardIntegrations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "switchboards",
            ":switchboardId",
            "switchboardIntegrations"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "switchboardId"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "8d11acac-f676-4126-9ead-4c6524fb9f64",
      "name": "Switchboard not found",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"bot\",\n    \"integrationType\": \"zd:agentWorkspace\",\n    \"deliverStandbyEvents\": true,\n    \"nextSwitchboardIntegrationId\": \"5ef21b86e933b7355c11c606\",\n    \"messageHistoryCount\": 5\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/switchboards/:switchboardId/switchboardIntegrations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "switchboards",
            ":switchboardId",
            "switchboardIntegrations"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "switchboardId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "e3926a73-1ec1-4910-b9b4-0ea1500954eb",
      "name": "Created",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"name\": \"bot\",\n    \"integrationType\": \"zd:agentWorkspace\",\n    \"deliverStandbyEvents\": true,\n    \"nextSwitchboardIntegrationId\": \"5ef21b86e933b7355c11c606\",\n    \"messageHistoryCount\": 5\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/switchboards/:switchboardId/switchboardIntegrations",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "switchboards",
            ":switchboardId",
            "switchboardIntegrations"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "switchboardId"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"switchboardIntegration\": {\n  \"id\": \"5ef21b86e933b7355c11c604\",\n  \"name\": \"bot\",\n  \"integrationId\": \"5ef21b86e933b7355c11c605\",\n  \"integrationType\": \"zd:agentWorkspace\",\n  \"deliverStandbyEvents\": true,\n  \"nextSwitchboardIntegrationId\": \"5ef21b86e933b7355c11c606\",\n  \"messageHistoryCount\": 5\n }\n}"
    }
  ]
}