Chilkat Online Tools

delphiAx / Squadcast API V3 / Get Routing Rules

Back to Collection Items

var
http: TChilkatHttp;
success: Integer;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
expression: WideString;
Entity_type: WideString;
Entity_id: WideString;
Id: WideString;
Created_at: WideString;
Updated_at: WideString;
Deleted_at: WideString;
Service_id: WideString;
Organization_id: WideString;
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 := TChilkatHttp.Create(Self);

http.SetRequestHeader('Authorization','');

sbResponseBody := TChilkatStringBuilder.Create(Self);
success := http.QuickGetSb('https://api.squadcast.com/v3/services/:serviceID/routing-rules',sbResponseBody.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(http.LastErrorText);
    Exit;
  end;

jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());

respStatusCode := http.LastStatus;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(http.LastHeader);
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": {
//     "id": "5d8b23427c870edd41453c25",
//     "created_at": "2019-09-25T08:20:18.884Z",
//     "updated_at": "2019-09-25T08:20:18.884Z",
//     "deleted_at": null,
//     "service_id": "5d81d9687000fb6b9def7e35",
//     "organization_id": "5d81d9187000fb6b9def7e32",
//     "rules": [
//       {
//         "expression": "re(current.labels.alertname, \"^CPUThrottlingHigh.*\") && re(past.labels.alertname, \"^CPUThrottlingHigh.*\")",
//         "route_to": {
//           "entity_type": "escalationpolicy",
//           "entity_id": "5d81d9407000fb6b9def7e33"
//         }
//       },
//       {
//         "expression": "re(current.labels.alertname, \"^CPUThrottlingHigh.*\") && re(past.labels.alertname, \"^CPUThrottlingHigh.*\")",
//         "route_to": {
//           "entity_type": "squad",
//           "entity_id": "5d8b5976578cc3b845cb3608"
//         }
//       },
//       {
//         "expression": "re(current.labels.alertname, \"^CPUThrottlingHigh.*\") && re(past.labels.alertname, \"^CPUThrottlingHigh.*\")",
//         "route_to": {
//           "entity_type": "user",
//           "entity_id": "5d81d9187000fb6b9def7e31"
//         }
//       }
//     ]
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

Id := jResp.StringOf('data.id');
Created_at := jResp.StringOf('data.created_at');
Updated_at := jResp.StringOf('data.updated_at');
Deleted_at := jResp.StringOf('data.deleted_at');
Service_id := jResp.StringOf('data.service_id');
Organization_id := jResp.StringOf('data.organization_id');
i := 0;
count_i := jResp.SizeOfArray('data.rules');
while i < count_i do
  begin
    jResp.I := i;
    expression := jResp.StringOf('data.rules[i].expression');
    Entity_type := jResp.StringOf('data.rules[i].route_to.entity_type');
    Entity_id := jResp.StringOf('data.rules[i].route_to.entity_id');
    i := i + 1;
  end;

Curl Command

curl -X GET
	-H "Authorization: "
https://api.squadcast.com/v3/services/:serviceID/routing-rules

Postman Collection Item JSON

{
  "name": "Get Routing Rules",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services/:serviceID/routing-rules",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services",
        ":serviceID",
        "routing-rules"
      ],
      "variable": [
        {
          "key": "serviceID",
          "value": "<string>",
          "type": "string",
          "description": "(Required) "
        }
      ]
    },
    "description": "This endpoint returns the default routing rules for the service if not already created.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
  },
  "response": [
    {
      "name": "Internal Server Error",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/routing-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "routing-rules"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/routing-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "routing-rules"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/routing-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "routing-rules"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": \"<integer>\",\n  \"error_message\": \"<string>\"\n }\n}"
    },
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/routing-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "routing-rules"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\n  \"id\": \"5d8b23427c870edd41453c25\",\n  \"created_at\": \"2019-09-25T08:20:18.884Z\",\n  \"updated_at\": \"2019-09-25T08:20:18.884Z\",\n  \"deleted_at\": null,\n  \"service_id\": \"5d81d9687000fb6b9def7e35\",\n  \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n  \"rules\": [\n   {\n    \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n    \"route_to\": {\n     \"entity_type\": \"escalationpolicy\",\n     \"entity_id\": \"5d81d9407000fb6b9def7e33\"\n    }\n   },\n   {\n    \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n    \"route_to\": {\n     \"entity_type\": \"squad\",\n     \"entity_id\": \"5d8b5976578cc3b845cb3608\"\n    }\n   },\n   {\n    \"expression\": \"re(current.labels.alertname, \\\"^CPUThrottlingHigh.*\\\") && re(past.labels.alertname, \\\"^CPUThrottlingHigh.*\\\")\",\n    \"route_to\": {\n     \"entity_type\": \"user\",\n     \"entity_id\": \"5d81d9187000fb6b9def7e31\"\n    }\n   }\n  ]\n }\n}"
    }
  ]
}