Chilkat Online Tools

C / Sunshine Conversations API / Update Conversation

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 *v_Type;
    const char *ActiveSwitchboardIntegrationId;
    const char *Name;
    const char *IntegrationId;
    const char *IntegrationType;
    const char *PendingSwitchboardIntegrationId;
    const char *PendingSwitchboardIntegrationName;
    const char *PendingSwitchboardIntegrationIntegrationId;
    const char *PendingSwitchboardIntegrationIntegrationType;
    BOOL IsDefault;
    const char *DisplayName;
    const char *Description;
    const char *IconUrl;
    const char *Lang;
    const char *BusinessLastRead;
    const char *LastUpdatedAt;

    // 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.

    // {
    //   "displayName": "elit",
    //   "description": "Conversation between Rogers and Carl.",
    //   "iconUrl": "https://www.gravatar.com/image.jpg",
    //   "metadata": {
    //     "lang": "en-ca"
    //   }
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"displayName","elit");
    CkJsonObject_UpdateString(json,"description","Conversation between Rogers and Carl.");
    CkJsonObject_UpdateString(json,"iconUrl","https://www.gravatar.com/image.jpg");
    CkJsonObject_UpdateString(json,"metadata.lang","en-ca");

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

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

    resp = CkHttp_PTextSb(http,"PATCH","https://domain.com/",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)

    // {
    //   "conversation": {
    //     "id": "c93bb9c14dde8ffb94564eae",
    //     "type": "personal",
    //     "activeSwitchboardIntegration": {
    //       "id": "5ef21b86e933b7355c11c604",
    //       "name": "bot",
    //       "integrationId": "5ef21b86e933b7355c11c605",
    //       "integrationType": "zd:agentWorkspace"
    //     },
    //     "pendingSwitchboardIntegration": {
    //       "id": "5ef21b86e933b7355c11c604",
    //       "name": "bot",
    //       "integrationId": "5ef21b86e933b7355c11c605",
    //       "integrationType": "zd:agentWorkspace"
    //     },
    //     "isDefault": false,
    //     "displayName": "pari",
    //     "description": "Conversation between Rogers and Carl.",
    //     "iconUrl": "https://www.gravatar.com/image.jpg",
    //     "metadata": {
    //       "lang": "en-ca"
    //     },
    //     "businessLastRead": "2020-06-23T14:33:47.492Z",
    //     "lastUpdatedAt": "2020-06-26T14:33:47.120Z"
    //   }
    // }

    // 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,"conversation.id");
    v_Type = CkJsonObject_stringOf(jResp,"conversation.type");
    ActiveSwitchboardIntegrationId = CkJsonObject_stringOf(jResp,"conversation.activeSwitchboardIntegration.id");
    Name = CkJsonObject_stringOf(jResp,"conversation.activeSwitchboardIntegration.name");
    IntegrationId = CkJsonObject_stringOf(jResp,"conversation.activeSwitchboardIntegration.integrationId");
    IntegrationType = CkJsonObject_stringOf(jResp,"conversation.activeSwitchboardIntegration.integrationType");
    PendingSwitchboardIntegrationId = CkJsonObject_stringOf(jResp,"conversation.pendingSwitchboardIntegration.id");
    PendingSwitchboardIntegrationName = CkJsonObject_stringOf(jResp,"conversation.pendingSwitchboardIntegration.name");
    PendingSwitchboardIntegrationIntegrationId = CkJsonObject_stringOf(jResp,"conversation.pendingSwitchboardIntegration.integrationId");
    PendingSwitchboardIntegrationIntegrationType = CkJsonObject_stringOf(jResp,"conversation.pendingSwitchboardIntegration.integrationType");
    IsDefault = CkJsonObject_BoolOf(jResp,"conversation.isDefault");
    DisplayName = CkJsonObject_stringOf(jResp,"conversation.displayName");
    Description = CkJsonObject_stringOf(jResp,"conversation.description");
    IconUrl = CkJsonObject_stringOf(jResp,"conversation.iconUrl");
    Lang = CkJsonObject_stringOf(jResp,"conversation.metadata.lang");
    BusinessLastRead = CkJsonObject_stringOf(jResp,"conversation.businessLastRead");
    LastUpdatedAt = CkJsonObject_stringOf(jResp,"conversation.lastUpdatedAt");


    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 '{
    "displayName": "elit",
    "description": "Conversation between Rogers and Carl.",
    "iconUrl": "https://www.gravatar.com/image.jpg",
    "metadata": {
        "lang": "en-ca"
    }
}'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Update Conversation",
  "_postman_id": "96737822-d414-42cf-a54c-b19311a3b68d",
  "request": {
    "method": "PATCH",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"displayName\": \"elit\",\n    \"description\": \"Conversation between Rogers and Carl.\",\n    \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n    \"metadata\": {\n        \"lang\": \"en-ca\"\n    }\n}"
    },
    "url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}",
    "description": "Updates a conversation record."
  },
  "response": [
    {
      "id": "f49e0f88-7c9f-4500-951a-95341d87cbb5",
      "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    \"displayName\": \"elit\",\n    \"description\": \"Conversation between Rogers and Carl.\",\n    \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n    \"metadata\": {\n        \"lang\": \"en-ca\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"conversation\": {\n  \"id\": \"c93bb9c14dde8ffb94564eae\",\n  \"type\": \"personal\",\n  \"activeSwitchboardIntegration\": {\n   \"id\": \"5ef21b86e933b7355c11c604\",\n   \"name\": \"bot\",\n   \"integrationId\": \"5ef21b86e933b7355c11c605\",\n   \"integrationType\": \"zd:agentWorkspace\"\n  },\n  \"pendingSwitchboardIntegration\": {\n   \"id\": \"5ef21b86e933b7355c11c604\",\n   \"name\": \"bot\",\n   \"integrationId\": \"5ef21b86e933b7355c11c605\",\n   \"integrationType\": \"zd:agentWorkspace\"\n  },\n  \"isDefault\": false,\n  \"displayName\": \"pari\",\n  \"description\": \"Conversation between Rogers and Carl.\",\n  \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n  \"metadata\": {\n   \"lang\": \"en-ca\"\n  },\n  \"businessLastRead\": \"2020-06-23T14:33:47.492Z\",\n  \"lastUpdatedAt\": \"2020-06-26T14:33:47.120Z\"\n }\n}"
    },
    {
      "id": "ffbec026-9563-44d8-afb5-d5aaa54230b9",
      "name": "Conversation not found",
      "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    \"displayName\": \"elit\",\n    \"description\": \"Conversation between Rogers and Carl.\",\n    \"iconUrl\": \"https://www.gravatar.com/image.jpg\",\n    \"metadata\": {\n        \"lang\": \"en-ca\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/conversations/:conversationId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations",
            ":conversationId"
          ],
          "variable": [
            {
              "key": "appId"
            },
            {
              "key": "conversationId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}