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.
-- {
-- "name": "Daily Backend schedule",
-- "colour": "#0f61dc",
-- "description": "This schedule repeats daily"
-- }
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, 'name', 'Daily Backend schedule'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'colour', '#0f61dc'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'description', 'This schedule repeats daily'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://api.squadcast.com/v3/schedules/:schedulesID', @sbRequestBody, 'utf-8', 'application/json', 0, 0
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
EXEC @hr = sp_OADestroy @sbRequestBody
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 @sbRequestBody
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": "5ecf73fbf92f2e731262b853",
-- "name": "Daily Backend schedule",
-- "slug": "daily-schedule",
-- "organization_id": "5d81d9187000fb6b9def7e32",
-- "colour": "#0f61dc",
-- "description": "This schedule repeats daily",
-- "organization": {
-- "id": "5d81d9187000fb6b9def7e32",
-- "name": "GopherHut",
-- "slug": "gopherhut"
-- }
-- }
-- }
-- 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)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'data.id'
DECLARE @Name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'data.name'
DECLARE @Slug nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Slug OUT, 'data.slug'
DECLARE @Organization_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Organization_id OUT, 'data.organization_id'
DECLARE @Colour nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Colour OUT, 'data.colour'
DECLARE @Description nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'data.description'
DECLARE @OrganizationId nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @OrganizationId OUT, 'data.organization.id'
DECLARE @OrganizationName nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @OrganizationName OUT, 'data.organization.name'
DECLARE @OrganizationSlug nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @OrganizationSlug OUT, 'data.organization.slug'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"name": "Daily Backend schedule",
"colour": "#0f61dc",
"description": "This schedule repeats daily"
}'
https://api.squadcast.com/v3/schedules/:schedulesID
Postman Collection Item JSON
{
"name": "Update Schedule",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853",
"type": "string"
}
]
},
"description": "This endpoint is used to update a schedule's configuration.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `schedule-write` scope."
},
"response": [
{
"name": "200 OK",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 08:37:30 GMT"
},
{
"key": "Content-Length",
"value": "294"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"id\": \"5ecf73fbf92f2e731262b853\",\n \"name\": \"Daily Backend schedule\",\n \"slug\": \"daily-schedule\",\n \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n \"colour\": \"#0f61dc\",\n \"description\": \"This schedule repeats daily\",\n \"organization\": {\n \"id\": \"5d81d9187000fb6b9def7e32\",\n \"name\": \"GopherHut\",\n \"slug\": \"gopherhut\"\n }\n }\n}"
},
{
"name": "409 Conflict",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:00:58 GMT"
},
{
"key": "Content-Length",
"value": "85"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 409,\n \"error_message\": \"schedule with the same name already exists\"\n }\n}"
},
{
"name": "400 Bad Request",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:01:26 GMT"
},
{
"key": "Content-Length",
"value": "56"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 400,\n \"error_message\": \"Name required\"\n }\n}"
},
{
"name": "401 Unauthorized",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:01:26 GMT"
},
{
"key": "Content-Length",
"value": "56"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 401,\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "500 Internal Server Error",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:01:26 GMT"
},
{
"key": "Content-Length",
"value": "56"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 500,\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "403 - Forbidden",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b853"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:01:26 GMT"
},
{
"key": "Content-Length",
"value": "56"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 403,\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "404 Not Found",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n\t\"name\": \"Daily Backend schedule\",\n\t\"colour\": \"#0f61dc\",\n\t\"description\": \"This schedule repeats daily\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/schedules/:schedulesID",
"host": [
"{{baseUrl}}"
],
"path": [
"schedules",
":schedulesID"
],
"variable": [
{
"key": "schedulesID",
"value": "5ecf73fbf92f2e731262b854"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "Date",
"value": "Thu, 28 May 2020 09:07:39 GMT"
},
{
"key": "Content-Length",
"value": "70"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": 404,\n \"error_message\": \"schedule resource not found\"\n }\n}"
}
]
}