Chilkat Online Tools

DataFlex / Squadcast API V3 / Create Schedules

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sId
    String sName
    String sSlug
    String sOrganization_id
    String sColour
    String sDescription
    String sOrganizationId
    String sOrganizationName
    String sOrganizationSlug
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "name" "Daily schedule" To iSuccess
    Get ComUpdateString Of hoJson "colour" "#0f61dd" To iSuccess
    Get ComUpdateString Of hoJson "description" "This schedule repeats daily" To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.squadcast.com/v3/schedules" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    Get ComStringOf Of hoJResp "data.id" To sId
    Get ComStringOf Of hoJResp "data.name" To sName
    Get ComStringOf Of hoJResp "data.slug" To sSlug
    Get ComStringOf Of hoJResp "data.organization_id" To sOrganization_id
    Get ComStringOf Of hoJResp "data.colour" To sColour
    Get ComStringOf Of hoJResp "data.description" To sDescription
    Get ComStringOf Of hoJResp "data.organization.id" To sOrganizationId
    Get ComStringOf Of hoJResp "data.organization.name" To sOrganizationName
    Get ComStringOf Of hoJResp "data.organization.slug" To sOrganizationSlug


End_Procedure

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