Chilkat Online Tools

unicodeC / Squadcast API V3 / Get Who Is On-Call

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 *first_name;
    const wchar_t *last_name;
    const wchar_t *email;
    const wchar_t *Dial_code;
    const wchar_t *Phone_number;
    const wchar_t *Shift_type;
    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/schedules/:schedulesID/on-call",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": {
    //     "shift_type": "Normal Shift",
    //     "users": [
    //       {
    //         "id": "5db927bbf8d4da1473169537",
    //         "first_name": "Tony",
    //         "last_name": "Stark",
    //         "email": "tony@squadcast.com",
    //         "contact": {
    //           "dial_code": "+91",
    //           "phone_number": "9578628779"
    //         }
    //       }
    //     ]
    //   }
    // }

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

    Shift_type = CkJsonObjectW_stringOf(jResp,L"data.shift_type");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.users");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        id = CkJsonObjectW_stringOf(jResp,L"data.users[i].id");
        first_name = CkJsonObjectW_stringOf(jResp,L"data.users[i].first_name");
        last_name = CkJsonObjectW_stringOf(jResp,L"data.users[i].last_name");
        email = CkJsonObjectW_stringOf(jResp,L"data.users[i].email");
        Dial_code = CkJsonObjectW_stringOf(jResp,L"data.users[i].contact.dial_code");
        Phone_number = CkJsonObjectW_stringOf(jResp,L"data.users[i].contact.phone_number");
        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/schedules/:schedulesID/on-call

Postman Collection Item JSON

{
  "name": "Get Who Is On-Call",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/schedules/:schedulesID/on-call",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "schedules",
        ":schedulesID",
        "on-call"
      ],
      "variable": [
        {
          "key": "schedulesID",
          "value": "5ecf7176f92f2e731262b852",
          "type": "string"
        }
      ]
    },
    "description": "This endpoint is used to get all the on-call users of the schedule.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `schedule-read` scope."
  },
  "response": [
    {
      "name": "200 OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/schedules/:schedulesID/on-call",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules",
            ":schedulesID",
            "on-call"
          ],
          "variable": [
            {
              "key": "schedulesID",
              "value": "5ecf7176f92f2e731262b852"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Date",
          "value": "Thu, 28 May 2020 09:18:21 GMT"
        },
        {
          "key": "Content-Length",
          "value": "50"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": {\n        \"shift_type\": \"Normal Shift\",\n        \"users\": [\n            {\n                \"id\": \"5db927bbf8d4da1473169537\",\n                \"first_name\": \"Tony\",\n                \"last_name\": \"Stark\",\n                \"email\": \"tony@squadcast.com\",\n                \"contact\": {\n                    \"dial_code\": \"+91\",\n                    \"phone_number\": \"9578628779\"\n                }\n            }\n        ]\n    }\n}"
    },
    {
      "name": "401 Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/schedules/:schedulesID/on-call",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules",
            ":schedulesID",
            "on-call"
          ],
          "variable": [
            {
              "key": "schedulesID",
              "value": "5ecf7176f92f2e731262b852"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Date",
          "value": "Thu, 28 May 2020 09:18:21 GMT"
        },
        {
          "key": "Content-Length",
          "value": "50"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 401,\n        \"error_message\": \"<string>\"\n    }\n}"
    }
  ]
}