PureBasic / Support API / List SLA Policies
Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
CkHttp::setCkBasicAuth(http, 1)
CkHttp::setCkLogin(http, "login")
CkHttp::setCkPassword(http, "password")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckQuickGetSb(http,"https://example.zendesk.com/api/v2/slas/policies",sbResponseBody)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
respStatusCode.i = CkHttp::ckLastStatus(http)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttp::ckLastHeader(http)
Debug "Failed."
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "count": "<integer>",
; "next_page": "<string>",
; "previous_page": "<string>",
; "sla_policies": [
; {
; "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>"
; },
; {
; "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
title.s
created_at.s
description.s
id.s
position.s
updated_at.s
url.s
j.i
count_j.i
field.s
operator.s
value.s
business_hours.s
metric.s
priority.s
target.s
count.s = CkJsonObject::ckStringOf(jResp,"count")
next_page.s = CkJsonObject::ckStringOf(jResp,"next_page")
previous_page.s = CkJsonObject::ckStringOf(jResp,"previous_page")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"sla_policies")
While i < count_i
CkJsonObject::setCkI(jResp, i)
title = CkJsonObject::ckStringOf(jResp,"sla_policies[i].title")
created_at = CkJsonObject::ckStringOf(jResp,"sla_policies[i].created_at")
description = CkJsonObject::ckStringOf(jResp,"sla_policies[i].description")
id = CkJsonObject::ckStringOf(jResp,"sla_policies[i].id")
position = CkJsonObject::ckStringOf(jResp,"sla_policies[i].position")
updated_at = CkJsonObject::ckStringOf(jResp,"sla_policies[i].updated_at")
url = CkJsonObject::ckStringOf(jResp,"sla_policies[i].url")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"sla_policies[i].filter.all")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
field = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.all[j].field")
operator = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.all[j].operator")
value = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.all[j].value")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"sla_policies[i].filter.any")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
field = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.any[j].field")
operator = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.any[j].operator")
value = CkJsonObject::ckStringOf(jResp,"sla_policies[i].filter.any[j].value")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"sla_policies[i].policy_metrics")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
business_hours = CkJsonObject::ckStringOf(jResp,"sla_policies[i].policy_metrics[j].business_hours")
metric = CkJsonObject::ckStringOf(jResp,"sla_policies[i].policy_metrics[j].metric")
priority = CkJsonObject::ckStringOf(jResp,"sla_policies[i].policy_metrics[j].priority")
target = CkJsonObject::ckStringOf(jResp,"sla_policies[i].policy_metrics[j].target")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -u login:password -X GET
-H "Accept: application/json"
https://example.zendesk.com/api/v2/slas/policies
Postman Collection Item JSON
{
"name": "List SLA Policies",
"request": {
"method": "GET",
"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": "Success response",
"originalRequest": {
"method": "GET",
"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": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"count\": \"<integer>\",\n \"next_page\": \"<string>\",\n \"previous_page\": \"<string>\",\n \"sla_policies\": [\n {\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 {\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 ]\n}"
}
]
}