Chilkat Online Tools

delphiDll / Support API / Update SLA Policy

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
field: PWideChar;
operator: PWideChar;
value: PWideChar;
business_hours: PWideChar;
metric: PWideChar;
priority: PWideChar;
target: PWideChar;
Title: PWideChar;
Created_at: PWideChar;
Description: PWideChar;
Id: PWideChar;
Position: PWideChar;
Updated_at: PWideChar;
v_Url: PWideChar;
i: Integer;
count_i: Integer;

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,'login');
CkHttp_putPassword(http,'password');

CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_QuickRequest(http,'PUT','https://example.zendesk.com/api/v2/slas/policies/:sla_policy_id');
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)

// {
//   "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

Title := CkJsonObject__stringOf(jResp,'sla_policy.title');
Created_at := CkJsonObject__stringOf(jResp,'sla_policy.created_at');
Description := CkJsonObject__stringOf(jResp,'sla_policy.description');
Id := CkJsonObject__stringOf(jResp,'sla_policy.id');
Position := CkJsonObject__stringOf(jResp,'sla_policy.position');
Updated_at := CkJsonObject__stringOf(jResp,'sla_policy.updated_at');
v_Url := CkJsonObject__stringOf(jResp,'sla_policy.url');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'sla_policy.filter.all');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    field := CkJsonObject__stringOf(jResp,'sla_policy.filter.all[i].field');
    operator := CkJsonObject__stringOf(jResp,'sla_policy.filter.all[i].operator');
    value := CkJsonObject__stringOf(jResp,'sla_policy.filter.all[i].value');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'sla_policy.filter.any');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    field := CkJsonObject__stringOf(jResp,'sla_policy.filter.any[i].field');
    operator := CkJsonObject__stringOf(jResp,'sla_policy.filter.any[i].operator');
    value := CkJsonObject__stringOf(jResp,'sla_policy.filter.any[i].value');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'sla_policy.policy_metrics');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    business_hours := CkJsonObject__stringOf(jResp,'sla_policy.policy_metrics[i].business_hours');
    metric := CkJsonObject__stringOf(jResp,'sla_policy.policy_metrics[i].metric');
    priority := CkJsonObject__stringOf(jResp,'sla_policy.policy_metrics[i].priority');
    target := CkJsonObject__stringOf(jResp,'sla_policy.policy_metrics[i].target');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl  -u login:password -X PUT
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/slas/policies/:sla_policy_id

Postman Collection Item JSON

{
  "name": "Update SLA Policy",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/slas/policies/:sla_policy_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "slas",
        "policies",
        ":sla_policy_id"
      ],
      "variable": [
        {
          "key": "sla_policy_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "Updates the specified policy.\n\n#### 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": "PUT",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/slas/policies/:sla_policy_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "slas",
            "policies",
            ":sla_policy_id"
          ],
          "variable": [
            {
              "key": "sla_policy_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_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}"
    }
  ]
}