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
DECLARE @iTmp0 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
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "email": "<string>",
-- "role": "<string>",
-- "first_name": "<string>",
-- "last_name": "<string>"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'email', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'role', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'first_name', '<string>'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'last_name', '<string>'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', ''
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.squadcast.com/v3/users', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "data": {
-- "id": "5e9c204dbde1298f6bcb5ef2",
-- "first_name": "Manigandan",
-- "last_name": "Dharmalingam",
-- "email": "manigandan@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
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @v_type nvarchar(4000)
DECLARE @time int
DECLARE @Id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data.id'
DECLARE @First_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @First_name OUT, 'data.first_name'
DECLARE @Last_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Last_name OUT, 'data.last_name'
DECLARE @v_Email nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'data.email'
DECLARE @Dial_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Dial_code OUT, 'data.contact.dial_code'
DECLARE @Phone_number nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Phone_number OUT, 'data.contact.phone_number'
DECLARE @Secondary_emails nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Secondary_emails OUT, 'data.secondary_emails'
DECLARE @Email_verified int
EXEC sp_OAMethod @jResp, 'BoolOf', @Email_verified OUT, 'data.email_verified'
DECLARE @Time_zone nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Time_zone OUT, 'data.time_zone'
DECLARE @Title nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Title OUT, 'data.title'
DECLARE @Bio nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Bio OUT, 'data.bio'
DECLARE @User_image int
EXEC sp_OAMethod @jResp, 'BoolOf', @User_image OUT, 'data.user_image'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'data.notification_rules'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'data.notification_rules[i].type'
EXEC sp_OAMethod @jResp, 'IntOf', @time OUT, 'data.notification_rules[i].time'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X POST
-H "Authorization: "
-H "Content-Type: application/json"
-d '{
"email": "<string>",
"role": "<string>",
"first_name": "<string>",
"last_name": "<string>"
}'
https://api.squadcast.com/v3/users
Postman Collection Item JSON
{
"name": "Add User",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Authorization",
"value": ""
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"<string>\",\n \"role\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\"\n}"
},
"url": {
"raw": "{{baseUrl}}/users",
"host": [
"{{baseUrl}}"
],
"path": [
"users"
]
},
"description": "Add user to the organization with given role if not exists. Returns the user object in response. \nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `user-write` scope."
},
"response": [
{
"name": "Unprocessable Entity",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"url": {
"raw": "{{baseUrl}}/users",
"host": [
"{{baseUrl}}"
],
"path": [
"users"
]
}
},
"status": "Unprocessable Entity (WebDAV) (RFC 4918)",
"code": 422,
"_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": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"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": "Created",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"url": {
"raw": "{{baseUrl}}/users",
"host": [
"{{baseUrl}}"
],
"path": [
"users"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"id\": \"5e9c204dbde1298f6bcb5ef2\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\",\n \"email\": \"manigandan@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 }\n}"
},
{
"name": "Bad Request",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"url": {
"raw": "{{baseUrl}}/users",
"host": [
"{{baseUrl}}"
],
"path": [
"users"
]
}
},
"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\": \"email required\"\n }\n}"
},
{
"name": "Conflict",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"url": {
"raw": "{{baseUrl}}/users",
"host": [
"{{baseUrl}}"
],
"path": [
"users"
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 409,\n \"error_message\": \"cannot add same user manigandan2293@gmail.com again to the organization\"\n }\n}"
},
{
"name": "Unauthorized",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"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\": 401,\n \"error_message\": \"invalid access token\"\n }\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"email\": \"manigandan@squadcast.com\",\n \"role\": \"admin\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\"\n}"
},
"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}"
}
]
}