Chilkat Online Tools

C / Sunshine Conversations API / Update Switchboard Integration

Back to Collection Items

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

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    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");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PATCH","https://domain.com/v2/apps/{{appId}}/switchboards/:switchboardId/switchboardIntegrations/:switchboardIntegrationId",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        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(sbRequestBody);
        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(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X PATCH
	-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/:switchboardIntegrationId

Postman Collection Item JSON

{
  "name": "Update Switchboard Integration",
  "_postman_id": "8bdfa234-93ff-4910-8436-4b820fcaeb45",
  "request": {
    "method": "PATCH",
    "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/:switchboardIntegrationId",
      "host": [
        "{{url}}"
      ],
      "path": [
        "v2",
        "apps",
        "{{appId}}",
        "switchboards",
        ":switchboardId",
        "switchboardIntegrations",
        ":switchboardIntegrationId"
      ],
      "variable": [
        {
          "key": "switchboardId"
        },
        {
          "key": "switchboardIntegrationId"
        }
      ]
    },
    "description": "Updates a switchboard integration record."
  },
  "response": [
    {
      "id": "779da036-39be-4849-853b-49a9485ea4fe",
      "name": "Ok",
      "originalRequest": {
        "method": "PATCH",
        "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/:switchboardIntegrationId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "switchboards",
            ":switchboardId",
            "switchboardIntegrations",
            ":switchboardIntegrationId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "switchboardId"
            },
            {
              "key": "switchboardIntegrationId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_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}"
    },
    {
      "id": "d52dad4e-71a0-4ab5-a58f-3568a48f608e",
      "name": "Enabled switchboard must have an associated default switchboardIntegration",
      "originalRequest": {
        "method": "PATCH",
        "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/:switchboardIntegrationId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "switchboards",
            ":switchboardId",
            "switchboardIntegrations",
            ":switchboardIntegrationId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "switchboardId"
            },
            {
              "key": "switchboardIntegrationId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}