Chilkat Online Tools

SQL Server / Squadcast API V3 / Get All Users

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', ''

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.squadcast.com/v3/users', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    DECLARE @id nvarchar(4000)

    DECLARE @first_name nvarchar(4000)

    DECLARE @last_name nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @Dial_code nvarchar(4000)

    DECLARE @Phone_number nvarchar(4000)

    DECLARE @email_verified int

    DECLARE @time_zone nvarchar(4000)

    DECLARE @title nvarchar(4000)

    DECLARE @bio nvarchar(4000)

    DECLARE @user_image int

    DECLARE @role_id nvarchar(4000)

    DECLARE @role nvarchar(4000)

    DECLARE @secondary_emails nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @v_type nvarchar(4000)

    DECLARE @time int

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'data[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @first_name OUT, 'data[i].first_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @last_name OUT, 'data[i].last_name'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'data[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @Dial_code OUT, 'data[i].contact.dial_code'
        EXEC sp_OAMethod @jResp, 'StringOf', @Phone_number OUT, 'data[i].contact.phone_number'
        EXEC sp_OAMethod @jResp, 'BoolOf', @email_verified OUT, 'data[i].email_verified'
        EXEC sp_OAMethod @jResp, 'StringOf', @time_zone OUT, 'data[i].time_zone'
        EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'data[i].title'
        EXEC sp_OAMethod @jResp, 'StringOf', @bio OUT, 'data[i].bio'
        EXEC sp_OAMethod @jResp, 'BoolOf', @user_image OUT, 'data[i].user_image'
        EXEC sp_OAMethod @jResp, 'StringOf', @role_id OUT, 'data[i].role_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @role OUT, 'data[i].role'
        EXEC sp_OAMethod @jResp, 'StringOf', @secondary_emails OUT, 'data[i].secondary_emails'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'data[i].secondary_emails'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            SELECT @j = @j + 1
          END
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'data[i].notification_rules'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'data[i].notification_rules[j].type'
            EXEC sp_OAMethod @jResp, 'IntOf', @time OUT, 'data[i].notification_rules[j].time'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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}"
    }
  ]
}