unicodeCpp / Support API / Create SLA Policy
Back to Collection Items
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
bool success;
http.put_BasicAuth(true);
http.put_Login(L"login");
http.put_Password(L"password");
http.SetRequestHeader(L"Accept",L"application/json");
CkHttpResponseW *resp = http.QuickRequest(L"POST",L"https://example.zendesk.com/api/v2/slas/policies");
if (http.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp->GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp->get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp->header());
wprintf(L"Failed.\n");
delete resp;
return;
}
delete resp;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "sla_policy": {
// "title": "<string>",
// "filter": {
// "all": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ],
// "any": [
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// },
// {
// "field": "<string>",
// "operator": "<string>",
// "value": "<string>"
// }
// ]
// },
// "created_at": "<dateTime>",
// "description": "<string>",
// "id": "<integer>",
// "policy_metrics": [
// {
// "business_hours": "<boolean>",
// "metric": "<string>",
// "priority": "<string>",
// "target": "<integer>"
// },
// {
// "business_hours": "<boolean>",
// "metric": "<string>",
// "priority": "<string>",
// "target": "<integer>"
// }
// ],
// "position": "<integer>",
// "updated_at": "<dateTime>",
// "url": "<string>"
// }
// }
// 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.
const wchar_t *field = 0;
const wchar_t *operator = 0;
const wchar_t *value = 0;
const wchar_t *business_hours = 0;
const wchar_t *metric = 0;
const wchar_t *priority = 0;
const wchar_t *target = 0;
const wchar_t *Title = jResp.stringOf(L"sla_policy.title");
const wchar_t *Created_at = jResp.stringOf(L"sla_policy.created_at");
const wchar_t *Description = jResp.stringOf(L"sla_policy.description");
const wchar_t *Id = jResp.stringOf(L"sla_policy.id");
const wchar_t *Position = jResp.stringOf(L"sla_policy.position");
const wchar_t *Updated_at = jResp.stringOf(L"sla_policy.updated_at");
const wchar_t *v_Url = jResp.stringOf(L"sla_policy.url");
int i = 0;
int count_i = jResp.SizeOfArray(L"sla_policy.filter.all");
while (i < count_i) {
jResp.put_I(i);
field = jResp.stringOf(L"sla_policy.filter.all[i].field");
operator = jResp.stringOf(L"sla_policy.filter.all[i].operator");
value = jResp.stringOf(L"sla_policy.filter.all[i].value");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"sla_policy.filter.any");
while (i < count_i) {
jResp.put_I(i);
field = jResp.stringOf(L"sla_policy.filter.any[i].field");
operator = jResp.stringOf(L"sla_policy.filter.any[i].operator");
value = jResp.stringOf(L"sla_policy.filter.any[i].value");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"sla_policy.policy_metrics");
while (i < count_i) {
jResp.put_I(i);
business_hours = jResp.stringOf(L"sla_policy.policy_metrics[i].business_hours");
metric = jResp.stringOf(L"sla_policy.policy_metrics[i].metric");
priority = jResp.stringOf(L"sla_policy.policy_metrics[i].priority");
target = jResp.stringOf(L"sla_policy.policy_metrics[i].target");
i = i + 1;
}
}
Curl Command
curl -u login:password -X POST
-H "Accept: application/json"
https://example.zendesk.com/api/v2/slas/policies
Postman Collection Item JSON
{
"name": "Create SLA Policy",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/slas/policies",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"slas",
"policies"
]
},
"description": "#### Availability\n\n* Accounts on the Support Professional or Suite Growth plan or above\n\n#### Allowed For\n\n* Admins\n"
},
"response": [
{
"name": "Created response",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/slas/policies",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"slas",
"policies"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"sla_policy\": {\n \"title\": \"<string>\",\n \"filter\": {\n \"all\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"any\": [\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n },\n {\n \"field\": \"<string>\",\n \"operator\": \"<string>\",\n \"value\": \"<string>\"\n }\n ]\n },\n \"created_at\": \"<dateTime>\",\n \"description\": \"<string>\",\n \"id\": \"<integer>\",\n \"policy_metrics\": [\n {\n \"business_hours\": \"<boolean>\",\n \"metric\": \"<string>\",\n \"priority\": \"<string>\",\n \"target\": \"<integer>\"\n },\n {\n \"business_hours\": \"<boolean>\",\n \"metric\": \"<string>\",\n \"priority\": \"<string>\",\n \"target\": \"<integer>\"\n }\n ],\n \"position\": \"<integer>\",\n \"updated_at\": \"<dateTime>\",\n \"url\": \"<string>\"\n }\n}"
}
]
}