Chilkat Online Tools

unicodeC / Squadcast API V3 / Get Service By ID

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 *Id;
    const wchar_t *Name;
    const wchar_t *Slug;
    const wchar_t *v_Email;
    const wchar_t *Escalation_policy_id;
    const wchar_t *Organization_id;
    const wchar_t *Api_key;
    const wchar_t *Description;
    const wchar_t *Depends;
    const wchar_t *Escalation_policyId;
    const wchar_t *Escalation_policyName;
    const wchar_t *Escalation_policyDescription;
    const wchar_t *Escalation_policySlug;

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

    http = CkHttpW_Create();

    CkHttpW_SetRequestHeader(http,L"Authorization",L"");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.squadcast.com/v3/services/:serviceID",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": "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"
    //     }
    //   }
    // }

    // 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");
    Name = CkJsonObjectW_stringOf(jResp,L"data.name");
    Slug = CkJsonObjectW_stringOf(jResp,L"data.slug");
    v_Email = CkJsonObjectW_stringOf(jResp,L"data.email");
    Escalation_policy_id = CkJsonObjectW_stringOf(jResp,L"data.escalation_policy_id");
    Organization_id = CkJsonObjectW_stringOf(jResp,L"data.organization_id");
    Api_key = CkJsonObjectW_stringOf(jResp,L"data.api_key");
    Description = CkJsonObjectW_stringOf(jResp,L"data.description");
    Depends = CkJsonObjectW_stringOf(jResp,L"data.depends");
    Escalation_policyId = CkJsonObjectW_stringOf(jResp,L"data.escalation_policy.id");
    Escalation_policyName = CkJsonObjectW_stringOf(jResp,L"data.escalation_policy.name");
    Escalation_policyDescription = CkJsonObjectW_stringOf(jResp,L"data.escalation_policy.description");
    Escalation_policySlug = CkJsonObjectW_stringOf(jResp,L"data.escalation_policy.slug");


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

    }

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get Service By ID",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/services/:serviceID",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "services",
        ":serviceID"
      ],
      "variable": [
        {
          "key": "serviceID",
          "value": "<string>",
          "type": "string",
          "description": "(Required) service id"
        }
      ]
    },
    "description": "Returns a service details of the given `serviceID` in the request param.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
  },
  "response": [
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "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": "Internal Server Error",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "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",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "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": "Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/services/:serviceID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_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",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "services",
            ":serviceID"
          ],
          "variable": [
            {
              "key": "serviceID"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\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}"
    }
  ]
}