Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
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.
// {
// "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"
// }
// }
var json = new chilkat.JsonObject();
json.UpdateString("type","personal");
json.UpdateString("participants[0].userId","42589ad070d43be9b00ff7e5");
json.UpdateBool("participants[0].subscribeSDKClient",false);
json.UpdateString("participants[1].userId","42589ad070d43be9b00ff7e5");
json.UpdateBool("participants[1].subscribeSDKClient",false);
json.UpdateString("displayName","nost");
json.UpdateString("description","Conversation between Rogers and Carl.");
json.UpdateString("iconUrl","https://www.gravatar.com/image.jpg");
json.UpdateString("metadata.lang","en-ca");
http.SetRequestHeader("Content-Type","application/json");
// resp: HttpResponse
var resp = http.PostJson3("https://domain.com/","application/json",json);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
var sbResponseBody = new chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
var jResp = new chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
console.log("Response Body:");
console.log(jResp.Emit());
var respStatusCode = resp.StatusCode;
console.log("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
console.log("Response Header:");
console.log(resp.Header);
console.log("Failed.");
return;
}
// 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
var Id = jResp.StringOf("conversation.id");
var v_Type = jResp.StringOf("conversation.type");
var ActiveSwitchboardIntegrationId = jResp.StringOf("conversation.activeSwitchboardIntegration.id");
var Name = jResp.StringOf("conversation.activeSwitchboardIntegration.name");
var IntegrationId = jResp.StringOf("conversation.activeSwitchboardIntegration.integrationId");
var IntegrationType = jResp.StringOf("conversation.activeSwitchboardIntegration.integrationType");
var PendingSwitchboardIntegrationId = jResp.StringOf("conversation.pendingSwitchboardIntegration.id");
var PendingSwitchboardIntegrationName = jResp.StringOf("conversation.pendingSwitchboardIntegration.name");
var PendingSwitchboardIntegrationIntegrationId = jResp.StringOf("conversation.pendingSwitchboardIntegration.integrationId");
var PendingSwitchboardIntegrationIntegrationType = jResp.StringOf("conversation.pendingSwitchboardIntegration.integrationType");
var IsDefault = jResp.BoolOf("conversation.isDefault");
var DisplayName = jResp.StringOf("conversation.displayName");
var Description = jResp.StringOf("conversation.description");
var IconUrl = jResp.StringOf("conversation.iconUrl");
var Lang = jResp.StringOf("conversation.metadata.lang");
var BusinessLastRead = jResp.StringOf("conversation.businessLastRead");
var LastUpdatedAt = jResp.StringOf("conversation.lastUpdatedAt");
}
chilkatExample();
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}"
}
]
}