Chilkat Online Tools

C / Squadcast API V3 / Get All Services

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject queryParams;
    HCkHttpResponse resp;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *id;
    const char *name;
    const char *slug;
    const char *email;
    const char *escalation_policy_id;
    const char *organization_id;
    const char *api_key;
    const char *description;
    const char *depends;
    const char *Id;
    const char *Name;
    const char *Description;
    const char *Slug;
    int i;
    int count_i;

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

    http = CkHttp_Create();

    queryParams = CkJsonObject_Create();
    CkJsonObject_UpdateString(queryParams,"name","");

    CkHttp_SetRequestHeader(http,"Authorization","");

    resp = CkHttp_QuickRequestParams(http,"GET","https://api.squadcast.com/v3/services",queryParams);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilder_Create();
    CkHttpResponse_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttpResponse_Dispose(resp);
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(queryParams);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    CkHttpResponse_Dispose(resp);

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

    // {
    //   "data": [
    //     {
    //       "id": "5e8edb24668e003cb0b18ba1",
    //       "name": "Payment API Service",
    //       "slug": "payment-api-service",
    //       "email": "unique_string@gopherhut.incidents.squadcast.com",
    //       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
    //       "organization_id": "5d81d9187000fb6b9def7e32",
    //       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43",
    //       "description": "Payment API Service monitor",
    //       "depends": null,
    //       "escalation_policy": {
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "name": "Example Escalation Policy",
    //         "description": "On-Boarding Example",
    //         "slug": "example-escalation-policy"
    //       }
    //     },
    //     {
    //       "id": "5e8edb24668e003cb0b18ba2",
    //       "name": "Notification Service",
    //       "slug": "notification-api-service",
    //       "email": "unique_string@gopherhut.incidents.squadcast.com",
    //       "escalation_policy_id": "5d81d9407000fb6b9def7e33",
    //       "organization_id": "5d81d9187000fb6b9def7e32",
    //       "api_key": "2f81ac8b2362990dd220f8bb4f7cd30ccc3d43",
    //       "description": "Notification API Service monitor",
    //       "depends": null,
    //       "escalation_policy": {
    //         "id": "5d81d9407000fb6b9def7e33",
    //         "name": "Example Escalation Policy",
    //         "description": "On-Boarding Example",
    //         "slug": "example-escalation-policy"
    //       }
    //     }
    //   ]
    // }

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

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"data");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        id = CkJsonObject_stringOf(jResp,"data[i].id");
        name = CkJsonObject_stringOf(jResp,"data[i].name");
        slug = CkJsonObject_stringOf(jResp,"data[i].slug");
        email = CkJsonObject_stringOf(jResp,"data[i].email");
        escalation_policy_id = CkJsonObject_stringOf(jResp,"data[i].escalation_policy_id");
        organization_id = CkJsonObject_stringOf(jResp,"data[i].organization_id");
        api_key = CkJsonObject_stringOf(jResp,"data[i].api_key");
        description = CkJsonObject_stringOf(jResp,"data[i].description");
        depends = CkJsonObject_stringOf(jResp,"data[i].depends");
        Id = CkJsonObject_stringOf(jResp,"data[i].escalation_policy.id");
        Name = CkJsonObject_stringOf(jResp,"data[i].escalation_policy.name");
        Description = CkJsonObject_stringOf(jResp,"data[i].escalation_policy.description");
        Slug = CkJsonObject_stringOf(jResp,"data[i].escalation_policy.slug");
        i = i + 1;
    }



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

    }

Curl Command

curl -G -d "name="
	-H "Authorization: "
https://api.squadcast.com/v3/services

Postman Collection Item JSON

{
  "name": "Get All Services",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services?name=",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services"
      ],
      "query": [
        {
          "key": "name",
          "value": ""
        }
      ]
    },
    "description": "Returns all the active services for the organization.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope.\n\nQuery Param:\n\n`name`: get a service by name"
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": [\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba1\",\n   \"name\": \"Payment API Service\",\n   \"slug\": \"payment-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3dac43\",\n   \"description\": \"Payment API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  },\n  {\n   \"id\": \"5e8edb24668e003cb0b18ba2\",\n   \"name\": \"Notification Service\",\n   \"slug\": \"notification-api-service\",\n   \"email\": \"unique_string@gopherhut.incidents.squadcast.com\",\n   \"escalation_policy_id\": \"5d81d9407000fb6b9def7e33\",\n   \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n   \"api_key\": \"2f81ac8b2362990dd220f8bb4f7cd30ccc3d43\",\n   \"description\": \"Notification API Service monitor\",\n   \"depends\": null,\n   \"escalation_policy\": {\n    \"id\": \"5d81d9407000fb6b9def7e33\",\n    \"name\": \"Example Escalation Policy\",\n    \"description\": \"On-Boarding Example\",\n    \"slug\": \"example-escalation-policy\"\n   }\n  }\n ]\n}"
    }
  ]
}