Chilkat Online Tools

unicodeC / Squadcast API V3 / Access Token

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 *Access_token;
    int Expires_at;
    int Issued_at;
    const wchar_t *Refresh_token;
    const wchar_t *v_Type;

    // 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"X-Refresh-Token",L"<string>");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://auth.squadcast.com/oauth/access-token",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": {
    //     "access_token": "eyJhbGciOiXXXXXXXXXXXXXX.eyJleHXXXXXXXXX.XXXXXXXXXXOwuvUNA",
    //     "expires_at": 1587412870,
    //     "issued_at": 1587240070,
    //     "refresh_token": "0d2a1a9a45XXXXXXXXXXXXXX3f134279",
    //     "type": "Bearer"
    //   }
    // }

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

    Access_token = CkJsonObjectW_stringOf(jResp,L"data.access_token");
    Expires_at = CkJsonObjectW_IntOf(jResp,L"data.expires_at");
    Issued_at = CkJsonObjectW_IntOf(jResp,L"data.issued_at");
    Refresh_token = CkJsonObjectW_stringOf(jResp,L"data.refresh_token");
    v_Type = CkJsonObjectW_stringOf(jResp,L"data.type");


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

    }

Curl Command

curl -X GET
	-H "X-Refresh-Token: <string>"
https://auth.squadcast.com/oauth/access-token

Postman Collection Item JSON

{
  "name": "Access Token",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "postman.clearGlobalVariable(\"access_token\");",
          "",
          "var jsonData = JSON.parse(responseBody);",
          "console.log(jsonData);",
          "",
          "",
          "if(responseCode.code === 200){",
          "   postman.setEnvironmentVariable(\"access_token\", jsonData.data.access_token);",
          "   postman.setGlobalVariable(\"access_token\", jsonData.data.access_token);",
          "   tests[\"Successful Login\"] = true;",
          "}else if(responseCode.code === 400){",
          "  tests[\"Invalid Credentials\"] =  false;",
          "}else{",
          "    tests[\"Failed Login\"] = true;",
          "}",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "description": "(Required) Send your refresh token optained from Squadcast web application.",
        "key": "X-Refresh-Token",
        "value": "<string>"
      }
    ],
    "url": {
      "raw": "https://auth.squadcast.com/oauth/access-token",
      "protocol": "https",
      "host": [
        "auth",
        "squadcast",
        "com"
      ],
      "path": [
        "oauth",
        "access-token"
      ]
    },
    "description": "Get access token to make authenticated HTTP requests to the Squadcast API."
  },
  "response": [
    {
      "name": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "X-Refresh-Token",
            "value": "<string>",
            "description": "(Required) Send your refresh token optained from Squadcast web application."
          }
        ],
        "url": {
          "raw": "https://auth.squadcast.com/oauth/access-token",
          "protocol": "https",
          "host": [
            "auth",
            "squadcast",
            "com"
          ],
          "path": [
            "oauth",
            "access-token"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\n  \"access_token\": \"eyJhbGciOiXXXXXXXXXXXXXX.eyJleHXXXXXXXXX.XXXXXXXXXXOwuvUNA\",\n  \"expires_at\": 1587412870,\n  \"issued_at\": 1587240070,\n  \"refresh_token\": \"0d2a1a9a45XXXXXXXXXXXXXX3f134279\",\n  \"type\": \"Bearer\"\n }\n}"
    },
    {
      "name": "Internal Server Error",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "X-Refresh-Token",
            "value": "<string>",
            "description": "(Required) Send your refresh token optained from Squadcast web application."
          }
        ],
        "url": {
          "raw": "https://auth.squadcast.com/oauth/access-token",
          "protocol": "https",
          "host": [
            "auth",
            "squadcast",
            "com"
          ],
          "path": [
            "oauth",
            "access-token"
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": 500,\n  \"error_message\": \"soemthing went wrong\"\n }\n}"
    },
    {
      "name": "Bad Request",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "X-Refresh-Token",
            "value": "<string>",
            "description": "(Required) Send your refresh token optained from Squadcast web application."
          }
        ],
        "url": {
          "raw": "https://auth.squadcast.com/oauth/access-token",
          "protocol": "https",
          "host": [
            "auth",
            "squadcast",
            "com"
          ],
          "path": [
            "oauth",
            "access-token"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"meta\": {\n  \"status\": 400,\n  \"error_message\": \"invalid refresh token\"\n }\n}"
    }
  ]
}