Chilkat Online Tools

PureBasic / Squadcast API V3 / Get All Users

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::ckSetRequestHeader(http,"Authorization","")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://api.squadcast.com/v3/users",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    ; 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,
    ;       "role_id": "5a425b383c36823b3ed91fb4",
    ;       "role": "account_owner"
    ;     },
    ;     {
    ;       "id": "5d91d262a2c85fa24a27d4d7",
    ;       "first_name": "Akilan",
    ;       "last_name": "Elango",
    ;       "email": "akilan@squadcast.com",
    ;       "contact": {
    ;         "dial_code": "",
    ;         "phone_number": ""
    ;       },
    ;       "secondary_emails": null,
    ;       "email_verified": false,
    ;       "time_zone": "",
    ;       "title": "",
    ;       "bio": "",
    ;       "notification_rules": [
    ;         {
    ;           "type": "Email",
    ;           "time": 0
    ;         },
    ;         {
    ;           "type": "Push",
    ;           "time": 0
    ;         },
    ;         {
    ;           "type": "SMS",
    ;           "time": 1
    ;         },
    ;         {
    ;           "type": "Phone",
    ;           "time": 2
    ;         }
    ;       ],
    ;       "user_image": false,
    ;       "role_id": "5a425b383c36823b3ed91fb5",
    ;       "role": "admin"
    ;     },
    ;     {
    ;       "id": "5d91d262a2c85fa24a27d4da",
    ;       "first_name": "Madhu",
    ;       "last_name": "DS Frontend",
    ;       "email": "madhu@squadcast.com",
    ;       "contact": {
    ;         "dial_code": "",
    ;         "phone_number": ""
    ;       },
    ;       "secondary_emails": null,
    ;       "email_verified": false,
    ;       "time_zone": "",
    ;       "title": "",
    ;       "bio": "",
    ;       "notification_rules": [
    ;         {
    ;           "type": "Email",
    ;           "time": 0
    ;         },
    ;         {
    ;           "type": "Push",
    ;           "time": 0
    ;         },
    ;         {
    ;           "type": "SMS",
    ;           "time": 1
    ;         },
    ;         {
    ;           "type": "Phone",
    ;           "time": 2
    ;         }
    ;       ],
    ;       "user_image": false,
    ;       "role_id": "5a425b383c36823b3ed91fb6",
    ;       "role": "user"
    ;     }
    ;   ]
    ; }

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

    id.s
    first_name.s
    last_name.s
    email.s
    Dial_code.s
    Phone_number.s
    email_verified.i
    time_zone.s
    title.s
    bio.s
    user_image.i
    role_id.s
    role.s
    secondary_emails.s
    j.i
    count_j.i
    v_type.s
    time.i

    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"data")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"data[i].id")
        first_name = CkJsonObject::ckStringOf(jResp,"data[i].first_name")
        last_name = CkJsonObject::ckStringOf(jResp,"data[i].last_name")
        email = CkJsonObject::ckStringOf(jResp,"data[i].email")
        Dial_code = CkJsonObject::ckStringOf(jResp,"data[i].contact.dial_code")
        Phone_number = CkJsonObject::ckStringOf(jResp,"data[i].contact.phone_number")
        email_verified = CkJsonObject::ckBoolOf(jResp,"data[i].email_verified")
        time_zone = CkJsonObject::ckStringOf(jResp,"data[i].time_zone")
        title = CkJsonObject::ckStringOf(jResp,"data[i].title")
        bio = CkJsonObject::ckStringOf(jResp,"data[i].bio")
        user_image = CkJsonObject::ckBoolOf(jResp,"data[i].user_image")
        role_id = CkJsonObject::ckStringOf(jResp,"data[i].role_id")
        role = CkJsonObject::ckStringOf(jResp,"data[i].role")
        secondary_emails = CkJsonObject::ckStringOf(jResp,"data[i].secondary_emails")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"data[i].secondary_emails")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"data[i].notification_rules")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            v_type = CkJsonObject::ckStringOf(jResp,"data[i].notification_rules[j].type")
            time = CkJsonObject::ckIntOf(jResp,"data[i].notification_rules[j].time")
            j = j + 1
        Wend
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

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

Postman Collection Item JSON

{
  "name": "Get All Users",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
      {
        "key": "Authorization",
        "value": ""
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/users",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "users"
      ]
    },
    "description": "Returns all the users of the organization.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope.\n        "
  },
  "response": [
    {
      "name": "Forbidden",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users"
          ]
        }
      },
      "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}}/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users"
          ]
        }
      },
      "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": "OK",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"data\": [\n  {\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   \"role_id\": \"5a425b383c36823b3ed91fb4\",\n   \"role\": \"account_owner\"\n  },\n  {\n   \"id\": \"5d91d262a2c85fa24a27d4d7\",\n   \"first_name\": \"Akilan\",\n   \"last_name\": \"Elango\",\n   \"email\": \"akilan@squadcast.com\",\n   \"contact\": {\n    \"dial_code\": \"\",\n    \"phone_number\": \"\"\n   },\n   \"secondary_emails\": null,\n   \"email_verified\": false,\n   \"time_zone\": \"\",\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   \"role_id\": \"5a425b383c36823b3ed91fb5\",\n   \"role\": \"admin\"\n  },\n  {\n   \"id\": \"5d91d262a2c85fa24a27d4da\",\n   \"first_name\": \"Madhu\",\n   \"last_name\": \"DS Frontend\",\n   \"email\": \"madhu@squadcast.com\",\n   \"contact\": {\n    \"dial_code\": \"\",\n    \"phone_number\": \"\"\n   },\n   \"secondary_emails\": null,\n   \"email_verified\": false,\n   \"time_zone\": \"\",\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   \"role_id\": \"5a425b383c36823b3ed91fb6\",\n   \"role\": \"user\"\n  }\n ]\n}"
    },
    {
      "name": "Unauthorized",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/users",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "users"
          ]
        }
      },
      "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}"
    }
  ]
}