Chilkat Online Tools

unicodeC / Squadcast API V3 / Get suppression rules

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *description;
    const wchar_t *expression;
    BOOL is_basic;
    const wchar_t *Id;
    const wchar_t *Created_at;
    const wchar_t *Updated_at;
    const wchar_t *Service_id;
    const wchar_t *Organization_id;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.squadcast.com/v3/services/:serviceID/suppression-rules",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

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

    // {
    //   "data": {
    //     "id": "5fa50748a2e7e47f1436c0fc",
    //     "created_at": "2020-11-06T08:20:24.756Z",
    //     "updated_at": "2020-11-11T09:28:19.972Z",
    //     "service_id": "5f8ed89e39e4a959da360537",
    //     "organization_id": "5db92749f8d4da1473169533",
    //     "rules": [
    //       {
    //         "description": "Suppress low latency alerts",
    //         "expression": "re(payload.policy_name, \"low latency\")",
    //         "is_basic": false
    //       }
    //     ]
    //   }
    // }

    // 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.

    Id = CkJsonObjectW_stringOf(jResp,L"data.id");
    Created_at = CkJsonObjectW_stringOf(jResp,L"data.created_at");
    Updated_at = CkJsonObjectW_stringOf(jResp,L"data.updated_at");
    Service_id = CkJsonObjectW_stringOf(jResp,L"data.service_id");
    Organization_id = CkJsonObjectW_stringOf(jResp,L"data.organization_id");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.rules");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        description = CkJsonObjectW_stringOf(jResp,L"data.rules[i].description");
        expression = CkJsonObjectW_stringOf(jResp,L"data.rules[i].expression");
        is_basic = CkJsonObjectW_BoolOf(jResp,L"data.rules[i].is_basic");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://api.squadcast.com/v3/services/:serviceID/suppression-rules

Postman Collection Item JSON

{
  "name": "Get suppression rules",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{sq_pb_auth_header}}",
          "type": "string"
        }
      ]
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services",
        ":serviceID",
        "suppression-rules"
      ],
      "variable": [
        {
          "key": "serviceID",
          "value": "5c7cf71ad517f500100b37d6",
          "type": "string"
        }
      ]
    },
    "description": "This endpoint returns the default suppression rules for the service if not already created. Requires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
  },
  "response": [
    {
      "name": "200 - suppression rules",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID/suppression-rules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID",
            "suppression-rules"
          ],
          "variable": [
            {
              "key": "serviceID",
              "value": ""
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Date",
          "value": "Fri, 18 Sep 2020 06:21:12 GMT"
        },
        {
          "key": "Content-Length",
          "value": "63"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": {\n        \"id\": \"5fa50748a2e7e47f1436c0fc\",\n        \"created_at\": \"2020-11-06T08:20:24.756Z\",\n        \"updated_at\": \"2020-11-11T09:28:19.972Z\",\n        \"service_id\": \"5f8ed89e39e4a959da360537\",\n        \"organization_id\": \"5db92749f8d4da1473169533\",\n        \"rules\": [\n            {\n                \"description\": \"Suppress low latency alerts\",\n                \"expression\": \"re(payload.policy_name, \\\"low latency\\\")\",\n                \"is_basic\": false\n            }\n        ]\n    }\n}"
    }
  ]
}