Chilkat Online Tools

TCL / Squadcast API V3 / Create Schedules

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

# 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 schedule",
#   "colour": "#0f61dd",
#   "description": "This schedule repeats daily"
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "name" "Daily schedule"
CkJsonObject_UpdateString $json "colour" "#0f61dd"
CkJsonObject_UpdateString $json "description" "This schedule repeats daily"

# Adds the "Authorization: Bearer <access_token>" header.
CkHttp_put_AuthToken $http "<access_token>"

# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://api.squadcast.com/v3/schedules" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

delete_CkHttpResponse $resp

# Sample JSON response:
# (Sample code for parsing the JSON response is shown below)

# {
#   "data": {
#     "id": "5ecf7176f92f2e731262b852",
#     "name": "Weekly schedule",
#     "slug": "weekly-schedule",
#     "organization_id": "5d81d9187000fb6b9def7e32",
#     "colour": "#0f61dd",
#     "description": "This schedule repeats weekly",
#     "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

set Id [CkJsonObject_stringOf $jResp "data.id"]
set Name [CkJsonObject_stringOf $jResp "data.name"]
set Slug [CkJsonObject_stringOf $jResp "data.slug"]
set Organization_id [CkJsonObject_stringOf $jResp "data.organization_id"]
set Colour [CkJsonObject_stringOf $jResp "data.colour"]
set Description [CkJsonObject_stringOf $jResp "data.description"]
set OrganizationId [CkJsonObject_stringOf $jResp "data.organization.id"]
set OrganizationName [CkJsonObject_stringOf $jResp "data.organization.name"]
set OrganizationSlug [CkJsonObject_stringOf $jResp "data.organization.slug"]

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
	"name": "Daily schedule",
	"colour": "#0f61dd",
	"description": "This schedule repeats daily"
}'
https://api.squadcast.com/v3/schedules

Postman Collection Item JSON

{
  "name": "Create Schedules",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"name\": \"Daily schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats daily\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/schedules",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "schedules"
      ]
    },
    "description": "This endpoint is used to create a new schedule.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `schedule-write` scope."
  },
  "response": [
    {
      "name": "201 Created",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats weekly\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/schedules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Date",
          "value": "Thu, 28 May 2020 08:08:24 GMT"
        },
        {
          "key": "Content-Length",
          "value": "289"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"data\": {\n        \"id\": \"5ecf7176f92f2e731262b852\",\n        \"name\": \"Weekly schedule\",\n        \"slug\": \"weekly-schedule\",\n        \"organization_id\": \"5d81d9187000fb6b9def7e32\",\n        \"colour\": \"#0f61dd\",\n        \"description\": \"This schedule repeats weekly\",\n        \"organization\": {\n            \"id\": \"5d81d9187000fb6b9def7e32\",\n            \"name\": \"GopherHut\",\n            \"slug\": \"gopherhut\"\n        }\n    }\n}"
    },
    {
      "name": "409 Conflict",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats weekly\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/schedules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules"
          ]
        }
      },
      "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 08:09:44 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": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats weekly\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/schedules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules"
          ]
        }
      },
      "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 08:10:13 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": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats weekly\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/schedules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules"
          ]
        }
      },
      "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 08:10:13 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": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"name\": \"Weekly schedule\",\n\t\"colour\": \"#0f61dd\",\n\t\"description\": \"This schedule repeats weekly\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/schedules",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "schedules"
          ]
        }
      },
      "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 08:10:13 GMT"
        },
        {
          "key": "Content-Length",
          "value": "56"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"meta\": {\n        \"status\": 500,\n        \"error_message\": \"<string>\"\n    }\n}"
    }
  ]
}