Chilkat Online Tools

PowerBuilder / Squadcast API V3 / Access Token

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Access_token
integer li_Expires_at
integer li_Issued_at
string ls_Refresh_token
string ls_V_Type

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.SetRequestHeader("X-Refresh-Token","<string>")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://auth.squadcast.com/oauth/access-token",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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

ls_Access_token = loo_JResp.StringOf("data.access_token")
li_Expires_at = loo_JResp.IntOf("data.expires_at")
li_Issued_at = loo_JResp.IntOf("data.issued_at")
ls_Refresh_token = loo_JResp.StringOf("data.refresh_token")
ls_V_Type = loo_JResp.StringOf("data.type")


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_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}"
    }
  ]
}