Chilkat Online Tools

PowerBuilder / Sunshine Conversations API / Create Conversation

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_V_Type
string ls_ActiveSwitchboardIntegrationId
string ls_Name
string ls_IntegrationId
string ls_IntegrationType
string ls_PendingSwitchboardIntegrationId
string ls_PendingSwitchboardIntegrationName
string ls_PendingSwitchboardIntegrationIntegrationId
string ls_PendingSwitchboardIntegrationIntegrationType
integer li_IsDefault
string ls_DisplayName
string ls_Description
string ls_IconUrl
string ls_Lang
string ls_BusinessLastRead
string ls_LastUpdatedAt

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.BasicAuth = 1
loo_Http.Login = "username"
loo_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.

// {
//   "type": "personal",
//   "participants": [
//     {
//       "userId": "42589ad070d43be9b00ff7e5",
//       "subscribeSDKClient": false
//     },
//     {
//       "userId": "42589ad070d43be9b00ff7e5",
//       "subscribeSDKClient": false
//     }
//   ],
//   "displayName": "nost",
//   "description": "Conversation between Rogers and Carl.",
//   "iconUrl": "https://www.gravatar.com/image.jpg",
//   "metadata": {
//     "lang": "en-ca"
//   }
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("type","personal")
loo_Json.UpdateString("participants[0].userId","42589ad070d43be9b00ff7e5")
loo_Json.UpdateBool("participants[0].subscribeSDKClient",0)
loo_Json.UpdateString("participants[1].userId","42589ad070d43be9b00ff7e5")
loo_Json.UpdateBool("participants[1].subscribeSDKClient",0)
loo_Json.UpdateString("displayName","nost")
loo_Json.UpdateString("description","Conversation between Rogers and Carl.")
loo_Json.UpdateString("iconUrl","https://www.gravatar.com/image.jpg")
loo_Json.UpdateString("metadata.lang","en-ca")

loo_Http.SetRequestHeader("Content-Type","application/json")

loo_Resp = loo_Http.PostJson3("https://domain.com/","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_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

ls_Id = loo_JResp.StringOf("conversation.id")
ls_V_Type = loo_JResp.StringOf("conversation.type")
ls_ActiveSwitchboardIntegrationId = loo_JResp.StringOf("conversation.activeSwitchboardIntegration.id")
ls_Name = loo_JResp.StringOf("conversation.activeSwitchboardIntegration.name")
ls_IntegrationId = loo_JResp.StringOf("conversation.activeSwitchboardIntegration.integrationId")
ls_IntegrationType = loo_JResp.StringOf("conversation.activeSwitchboardIntegration.integrationType")
ls_PendingSwitchboardIntegrationId = loo_JResp.StringOf("conversation.pendingSwitchboardIntegration.id")
ls_PendingSwitchboardIntegrationName = loo_JResp.StringOf("conversation.pendingSwitchboardIntegration.name")
ls_PendingSwitchboardIntegrationIntegrationId = loo_JResp.StringOf("conversation.pendingSwitchboardIntegration.integrationId")
ls_PendingSwitchboardIntegrationIntegrationType = loo_JResp.StringOf("conversation.pendingSwitchboardIntegration.integrationType")
li_IsDefault = loo_JResp.BoolOf("conversation.isDefault")
ls_DisplayName = loo_JResp.StringOf("conversation.displayName")
ls_Description = loo_JResp.StringOf("conversation.description")
ls_IconUrl = loo_JResp.StringOf("conversation.iconUrl")
ls_Lang = loo_JResp.StringOf("conversation.metadata.lang")
ls_BusinessLastRead = loo_JResp.StringOf("conversation.businessLastRead")
ls_LastUpdatedAt = loo_JResp.StringOf("conversation.lastUpdatedAt")


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -X POST
	-u 'username:password'
	-H "Content-Type: application/json"
	-d '{
    "type": "personal",
    "participants": [
        {
            "userId": "42589ad070d43be9b00ff7e5",
            "subscribeSDKClient": false
        },
        {
            "userId": "42589ad070d43be9b00ff7e5",
            "subscribeSDKClient": false
        }
    ],
    "displayName": "nost",
    "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": "Create Conversation",
  "_postman_id": "6688103e-1c82-402c-9e0f-4b96cca896b4",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"type\": \"personal\",\n    \"participants\": [\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        },\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        }\n    ],\n    \"displayName\": \"nost\",\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",
    "description": "Create a conversation for the specified user(s)."
  },
  "response": [
    {
      "id": "04d65a14-1557-46bb-a278-f68f4139173c",
      "name": "App 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    \"type\": \"personal\",\n    \"participants\": [\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        },\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        }\n    ],\n    \"displayName\": \"nost\",\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",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations"
          ],
          "variable": [
            {
              "key": "appId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "id": "cb8fc1a2-02f1-4c6b-8a0c-311004d1d2ba",
      "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    \"type\": \"personal\",\n    \"participants\": [\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        },\n        {\n            \"userId\": \"42589ad070d43be9b00ff7e5\",\n            \"subscribeSDKClient\": false\n        }\n    ],\n    \"displayName\": \"nost\",\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",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "conversations"
          ],
          "variable": [
            {
              "key": "appId"
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_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}"
    }
  ]
}