Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *Id;
const wchar_t *v_Type;
const wchar_t *ActiveSwitchboardIntegrationId;
const wchar_t *Name;
const wchar_t *IntegrationId;
const wchar_t *IntegrationType;
const wchar_t *PendingSwitchboardIntegrationId;
const wchar_t *PendingSwitchboardIntegrationName;
const wchar_t *PendingSwitchboardIntegrationIntegrationId;
const wchar_t *PendingSwitchboardIntegrationIntegrationType;
BOOL IsDefault;
const wchar_t *DisplayName;
const wchar_t *Description;
const wchar_t *IconUrl;
const wchar_t *Lang;
const wchar_t *BusinessLastRead;
const wchar_t *LastUpdatedAt;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putBasicAuth(http,TRUE);
CkHttpW_putLogin(http,L"username");
CkHttpW_putPassword(http,L"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"
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"type",L"personal");
CkJsonObjectW_UpdateString(json,L"participants[0].userId",L"42589ad070d43be9b00ff7e5");
CkJsonObjectW_UpdateBool(json,L"participants[0].subscribeSDKClient",FALSE);
CkJsonObjectW_UpdateString(json,L"participants[1].userId",L"42589ad070d43be9b00ff7e5");
CkJsonObjectW_UpdateBool(json,L"participants[1].subscribeSDKClient",FALSE);
CkJsonObjectW_UpdateString(json,L"displayName",L"nost");
CkJsonObjectW_UpdateString(json,L"description",L"Conversation between Rogers and Carl.");
CkJsonObjectW_UpdateString(json,L"iconUrl",L"https://www.gravatar.com/image.jpg");
CkJsonObjectW_UpdateString(json,L"metadata.lang",L"en-ca");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
resp = CkHttpW_PostJson3(http,L"https://domain.com/",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
sbResponseBody = CkStringBuilderW_Create();
CkHttpResponseW_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbResponseBody);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
respStatusCode = CkHttpResponseW_getStatusCode(resp);
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"Failed.\n");
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
CkHttpResponseW_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 = CkJsonObjectW_stringOf(jResp,L"conversation.id");
v_Type = CkJsonObjectW_stringOf(jResp,L"conversation.type");
ActiveSwitchboardIntegrationId = CkJsonObjectW_stringOf(jResp,L"conversation.activeSwitchboardIntegration.id");
Name = CkJsonObjectW_stringOf(jResp,L"conversation.activeSwitchboardIntegration.name");
IntegrationId = CkJsonObjectW_stringOf(jResp,L"conversation.activeSwitchboardIntegration.integrationId");
IntegrationType = CkJsonObjectW_stringOf(jResp,L"conversation.activeSwitchboardIntegration.integrationType");
PendingSwitchboardIntegrationId = CkJsonObjectW_stringOf(jResp,L"conversation.pendingSwitchboardIntegration.id");
PendingSwitchboardIntegrationName = CkJsonObjectW_stringOf(jResp,L"conversation.pendingSwitchboardIntegration.name");
PendingSwitchboardIntegrationIntegrationId = CkJsonObjectW_stringOf(jResp,L"conversation.pendingSwitchboardIntegration.integrationId");
PendingSwitchboardIntegrationIntegrationType = CkJsonObjectW_stringOf(jResp,L"conversation.pendingSwitchboardIntegration.integrationType");
IsDefault = CkJsonObjectW_BoolOf(jResp,L"conversation.isDefault");
DisplayName = CkJsonObjectW_stringOf(jResp,L"conversation.displayName");
Description = CkJsonObjectW_stringOf(jResp,L"conversation.description");
IconUrl = CkJsonObjectW_stringOf(jResp,L"conversation.iconUrl");
Lang = CkJsonObjectW_stringOf(jResp,L"conversation.metadata.lang");
BusinessLastRead = CkJsonObjectW_stringOf(jResp,L"conversation.businessLastRead");
LastUpdatedAt = CkJsonObjectW_stringOf(jResp,L"conversation.lastUpdatedAt");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(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}"
}
]
}