Back to Collection Items
var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
Id: PWideChar;
DisplayName: PWideChar;
ConversationRetentionSeconds: Integer;
MaskCreditCardNumbers: Boolean;
UseAnimalNames: Boolean;
EchoPostback: Boolean;
IgnoreAutoConversationStart: Boolean;
MultiConvoEnabled: Boolean;
AttachmentsAccess: PWideChar;
AttachmentsTokenExpirationSeconds: Integer;
Lang: PWideChar;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
CkHttp_putBasicAuth(http,True);
CkHttp_putLogin(http,'username');
CkHttp_putPassword(http,'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": "proi",
// "settings": {
// "conversationRetentionSeconds": 12466975,
// "maskCreditCardNumbers": false,
// "useAnimalNames": true,
// "echoPostback": false,
// "ignoreAutoConversationStart": false,
// "multiConvoEnabled": false,
// "attachmentsAccess": "public",
// "attachmentsTokenExpirationSeconds": 64028
// },
// "metadata": {
// "lang": "en-ca"
// }
// }
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'displayName','proi');
CkJsonObject_UpdateInt(json,'settings.conversationRetentionSeconds',12466975);
CkJsonObject_UpdateBool(json,'settings.maskCreditCardNumbers',False);
CkJsonObject_UpdateBool(json,'settings.useAnimalNames',True);
CkJsonObject_UpdateBool(json,'settings.echoPostback',False);
CkJsonObject_UpdateBool(json,'settings.ignoreAutoConversationStart',False);
CkJsonObject_UpdateBool(json,'settings.multiConvoEnabled',False);
CkJsonObject_UpdateString(json,'settings.attachmentsAccess','public');
CkJsonObject_UpdateInt(json,'settings.attachmentsTokenExpirationSeconds',64028);
CkJsonObject_UpdateString(json,'metadata.lang','en-ca');
CkHttp_SetRequestHeader(http,'Content-Type','application/json');
resp := CkHttp_PostJson3(http,'https://domain.com/','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));
respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkHttpResponse__header(resp));
Memo1.Lines.Add('Failed.');
CkHttpResponse_Dispose(resp);
Exit;
end;
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "app": {
// "id": "5d8cff3cd55b040010928b5b",
// "displayName": "utoc",
// "settings": {
// "conversationRetentionSeconds": 35855812,
// "maskCreditCardNumbers": true,
// "useAnimalNames": false,
// "echoPostback": true,
// "ignoreAutoConversationStart": true,
// "multiConvoEnabled": true,
// "attachmentsAccess": "public",
// "attachmentsTokenExpirationSeconds": 64028
// },
// "metadata": {
// "lang": "en-ca"
// }
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Id := CkJsonObject__stringOf(jResp,'app.id');
DisplayName := CkJsonObject__stringOf(jResp,'app.displayName');
ConversationRetentionSeconds := CkJsonObject_IntOf(jResp,'app.settings.conversationRetentionSeconds');
MaskCreditCardNumbers := CkJsonObject_BoolOf(jResp,'app.settings.maskCreditCardNumbers');
UseAnimalNames := CkJsonObject_BoolOf(jResp,'app.settings.useAnimalNames');
EchoPostback := CkJsonObject_BoolOf(jResp,'app.settings.echoPostback');
IgnoreAutoConversationStart := CkJsonObject_BoolOf(jResp,'app.settings.ignoreAutoConversationStart');
MultiConvoEnabled := CkJsonObject_BoolOf(jResp,'app.settings.multiConvoEnabled');
AttachmentsAccess := CkJsonObject__stringOf(jResp,'app.settings.attachmentsAccess');
AttachmentsTokenExpirationSeconds := CkJsonObject_IntOf(jResp,'app.settings.attachmentsTokenExpirationSeconds');
Lang := CkJsonObject__stringOf(jResp,'app.metadata.lang');
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
Curl Command
curl -X POST
-u 'username:password'
-H "Content-Type: application/json"
-d '{
"displayName": "proi",
"settings": {
"conversationRetentionSeconds": 12466975,
"maskCreditCardNumbers": false,
"useAnimalNames": true,
"echoPostback": false,
"ignoreAutoConversationStart": false,
"multiConvoEnabled": false,
"attachmentsAccess": "public",
"attachmentsTokenExpirationSeconds": 64028
},
"metadata": {
"lang": "en-ca"
}
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "Create App",
"_postman_id": "4e199592-ca64-47d6-ad91-f5a1a05abfb2",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"displayName\": \"proi\",\n \"settings\": {\n \"conversationRetentionSeconds\": 12466975,\n \"maskCreditCardNumbers\": false,\n \"useAnimalNames\": true,\n \"echoPostback\": false,\n \"ignoreAutoConversationStart\": false,\n \"multiConvoEnabled\": false,\n \"attachmentsAccess\": \"public\",\n \"attachmentsTokenExpirationSeconds\": 64028\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{url}}/v2/apps",
"description": "Creates a new app. When using [service account](#service-accounts) credentials, the service account is automatically granted access to the app."
},
"response": [
{
"id": "17a454e4-dc50-4600-8337-693271b27f98",
"name": "Your account has reached the maximum number of apps for your subscription plan",
"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 \"displayName\": \"proi\",\n \"settings\": {\n \"conversationRetentionSeconds\": 12466975,\n \"maskCreditCardNumbers\": false,\n \"useAnimalNames\": true,\n \"echoPostback\": false,\n \"ignoreAutoConversationStart\": false,\n \"multiConvoEnabled\": false,\n \"attachmentsAccess\": \"public\",\n \"attachmentsTokenExpirationSeconds\": 64028\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{baseUrl}}/v2/apps"
},
"status": "Payment Required",
"code": 402,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"id": "288fc92e-2d6f-46cf-b38e-856fc5946b5d",
"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 \"displayName\": \"proi\",\n \"settings\": {\n \"conversationRetentionSeconds\": 12466975,\n \"maskCreditCardNumbers\": false,\n \"useAnimalNames\": true,\n \"echoPostback\": false,\n \"ignoreAutoConversationStart\": false,\n \"multiConvoEnabled\": false,\n \"attachmentsAccess\": \"public\",\n \"attachmentsTokenExpirationSeconds\": 64028\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{baseUrl}}/v2/apps"
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"app\": {\n \"id\": \"5d8cff3cd55b040010928b5b\",\n \"displayName\": \"utoc\",\n \"settings\": {\n \"conversationRetentionSeconds\": 35855812,\n \"maskCreditCardNumbers\": true,\n \"useAnimalNames\": false,\n \"echoPostback\": true,\n \"ignoreAutoConversationStart\": true,\n \"multiConvoEnabled\": true,\n \"attachmentsAccess\": \"public\",\n \"attachmentsTokenExpirationSeconds\": 64028\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n }\n}"
},
{
"id": "d62f7132-159c-4532-bd7b-30c6060718a1",
"name": "should have required property 'displayName'",
"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 \"displayName\": \"proi\",\n \"settings\": {\n \"conversationRetentionSeconds\": 12466975,\n \"maskCreditCardNumbers\": false,\n \"useAnimalNames\": true,\n \"echoPostback\": false,\n \"ignoreAutoConversationStart\": false,\n \"multiConvoEnabled\": false,\n \"attachmentsAccess\": \"public\",\n \"attachmentsTokenExpirationSeconds\": 64028\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{baseUrl}}/v2/apps"
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}