Chilkat Online Tools

PowerBuilder / Squadcast API V3 / Get User By ID

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_V_type
integer li_Time
string ls_Id
string ls_First_name
string ls_Last_name
string ls_V_Email
string ls_Dial_code
string ls_Phone_number
integer li_Email_verified
string ls_Time_zone
string ls_Title
string ls_Bio
integer li_User_image
integer i
integer li_Count_i

// 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("Authorization","")

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

li_Success = loo_Http.QuickGetSb("https://api.squadcast.com/v3users/:userID",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": {
//     "id": "5d81d9187000fb6b9def7e31",
//     "first_name": "Manigandan",
//     "last_name": "Dharmalingam",
//     "email": "manigandan@squadcast.com",
//     "contact": {
//       "dial_code": "+91",
//       "phone_number": "9578628779"
//     },
//     "secondary_emails": [
//     ],
//     "email_verified": true,
//     "time_zone": "Asia/Calcutta",
//     "title": "",
//     "bio": "",
//     "notification_rules": [
//       {
//         "type": "Email",
//         "time": 0
//       },
//       {
//         "type": "Push",
//         "time": 0
//       },
//       {
//         "type": "SMS",
//         "time": 1
//       },
//       {
//         "type": "Phone",
//         "time": 2
//       }
//     ],
//     "user_image": false
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

ls_Id = loo_JResp.StringOf("data.id")
ls_First_name = loo_JResp.StringOf("data.first_name")
ls_Last_name = loo_JResp.StringOf("data.last_name")
ls_V_Email = loo_JResp.StringOf("data.email")
ls_Dial_code = loo_JResp.StringOf("data.contact.dial_code")
ls_Phone_number = loo_JResp.StringOf("data.contact.phone_number")
li_Email_verified = loo_JResp.BoolOf("data.email_verified")
ls_Time_zone = loo_JResp.StringOf("data.time_zone")
ls_Title = loo_JResp.StringOf("data.title")
ls_Bio = loo_JResp.StringOf("data.bio")
li_User_image = loo_JResp.BoolOf("data.user_image")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.secondary_emails")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.notification_rules")
do while i < li_Count_i
    loo_JResp.I = i
    ls_V_type = loo_JResp.StringOf("data.notification_rules[i].type")
    li_Time = loo_JResp.IntOf("data.notification_rules[i].time")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -X GET
	-H "Authorization: "
https://api.squadcast.com/v3users/:userID

Postman Collection Item JSON

{
  "name": "Get User By ID",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}users/:userID",
      "host": [
        "{{baseUrl}}users"
      ],
      "path": [
        ":userID"
      ],
      "variable": [
        {
          "key": "userID",
          "value": "<string>",
          "type": "string",
          "description": "(Required) user id"
        }
      ]
    },
    "description": "Returns a users details of the given `userID` in the request param.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
  },
  "response": [
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users/:userID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users",
            ":userID"
          ],
          "variable": [
            {
              "key": "userID"
            }
          ]
        }
      },
      "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": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users/:userID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users",
            ":userID"
          ],
          "variable": [
            {
              "key": "userID"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": {\n  \"id\": \"5d81d9187000fb6b9def7e31\",\n  \"first_name\": \"Manigandan\",\n  \"last_name\": \"Dharmalingam\",\n  \"email\": \"manigandan@squadcast.com\",\n  \"contact\": {\n   \"dial_code\": \"+91\",\n   \"phone_number\": \"9578628779\"\n  },\n  \"secondary_emails\": [],\n  \"email_verified\": true,\n  \"time_zone\": \"Asia/Calcutta\",\n  \"title\": \"\",\n  \"bio\": \"\",\n  \"notification_rules\": [\n   {\n    \"type\": \"Email\",\n    \"time\": 0\n   },\n   {\n    \"type\": \"Push\",\n    \"time\": 0\n   },\n   {\n    \"type\": \"SMS\",\n    \"time\": 1\n   },\n   {\n    \"type\": \"Phone\",\n    \"time\": 2\n   }\n  ],\n  \"user_image\": false\n }\n}"
    },
    {
      "name": "Not Found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users/:userID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users",
            ":userID"
          ],
          "variable": [
            {
              "key": "userID"
            }
          ]
        }
      },
      "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": "Internal Server Error",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users/:userID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users",
            ":userID"
          ],
          "variable": [
            {
              "key": "userID"
            }
          ]
        }
      },
      "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": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users/:userID",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users",
            ":userID"
          ],
          "variable": [
            {
              "key": "userID"
            }
          ]
        }
      },
      "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}"
    }
  ]
}