Chilkat Online Tools

Xojo / Sunshine Conversations API / Update Conversation

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

http.BasicAuth = True
http.Login = "username"
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.

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

Dim json As New Chilkat.JsonObject
success = json.UpdateString("displayName","elit")
success = json.UpdateString("description","Conversation between Rogers and Carl.")
success = json.UpdateString("iconUrl","https://www.gravatar.com/image.jpg")
success = json.UpdateString("metadata.lang","en-ca")

http.SetRequestHeader "Content-Type","application/json"

Dim sbRequestBody As New Chilkat.StringBuilder
success = json.EmitSb(sbRequestBody)

Dim resp As Chilkat.HttpResponse
resp = http.PTextSb("PATCH","https://domain.com/",sbRequestBody,"utf-8","application/json",False,False)
If (http.LastMethodSuccess = False) Then
    System.DebugLog(http.LastErrorText)
    Return
End If

Dim sbResponseBody As New Chilkat.StringBuilder
success = resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

System.DebugLog("Response Body:")
System.DebugLog(jResp.Emit())

Dim respStatusCode As Int32
respStatusCode = resp.StatusCode
System.DebugLog("Response Status Code = " + Str(respStatusCode))
If (respStatusCode >= 400) Then
    System.DebugLog("Response Header:")
    System.DebugLog(resp.Header)
    System.DebugLog("Failed.")

    Return
End If

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

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

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": ""
    }
  ]
}