Chilkat Online Tools

delphiAx / Sunshine Conversations API / Get Conversation

Back to Collection Items

var
http: TChilkatHttp;
success: Integer;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
Id: WideString;
v_Type: WideString;
ActiveSwitchboardIntegrationId: WideString;
Name: WideString;
IntegrationId: WideString;
IntegrationType: WideString;
PendingSwitchboardIntegrationId: WideString;
PendingSwitchboardIntegrationName: WideString;
PendingSwitchboardIntegrationIntegrationId: WideString;
PendingSwitchboardIntegrationIntegrationType: WideString;
IsDefault: Integer;
DisplayName: WideString;
Description: WideString;
IconUrl: WideString;
Lang: WideString;
BusinessLastRead: WideString;
LastUpdatedAt: WideString;

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

http := TChilkatHttp.Create(Self);

http.BasicAuth := 1;
http.Login := 'username';
http.Password := 'password';

sbResponseBody := TChilkatStringBuilder.Create(Self);
success := http.QuickGetSb('https://domain.com/',sbResponseBody.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(http.LastErrorText);
    Exit;
  end;

jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());

respStatusCode := http.LastStatus;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(http.LastHeader);
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

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

Id := jResp.StringOf('conversation.id');
v_Type := jResp.StringOf('conversation.type');
ActiveSwitchboardIntegrationId := jResp.StringOf('conversation.activeSwitchboardIntegration.id');
Name := jResp.StringOf('conversation.activeSwitchboardIntegration.name');
IntegrationId := jResp.StringOf('conversation.activeSwitchboardIntegration.integrationId');
IntegrationType := jResp.StringOf('conversation.activeSwitchboardIntegration.integrationType');
PendingSwitchboardIntegrationId := jResp.StringOf('conversation.pendingSwitchboardIntegration.id');
PendingSwitchboardIntegrationName := jResp.StringOf('conversation.pendingSwitchboardIntegration.name');
PendingSwitchboardIntegrationIntegrationId := jResp.StringOf('conversation.pendingSwitchboardIntegration.integrationId');
PendingSwitchboardIntegrationIntegrationType := jResp.StringOf('conversation.pendingSwitchboardIntegration.integrationType');
IsDefault := jResp.BoolOf('conversation.isDefault');
DisplayName := jResp.StringOf('conversation.displayName');
Description := jResp.StringOf('conversation.description');
IconUrl := jResp.StringOf('conversation.iconUrl');
Lang := jResp.StringOf('conversation.metadata.lang');
BusinessLastRead := jResp.StringOf('conversation.businessLastRead');
LastUpdatedAt := jResp.StringOf('conversation.lastUpdatedAt');

Curl Command

curl -X GET
	-u 'username:password'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Get Conversation",
  "_postman_id": "ffbb4dbd-fbf6-43f4-9e0c-6be5c4e2829c",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": "{{url}}/v2/apps/{{appId}}/conversations/{{conversationId}}",
    "description": "Fetches an individual conversation."
  },
  "response": [
    {
      "id": "90c0f930-c5be-456b-93fd-2d14edac480c",
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "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": "d66e4f40-123a-4f32-8858-445be2b989d3",
      "name": "Conversation not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "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": ""
    }
  ]
}