Using the endpoints

In this tutorial we will teach you how to setup and request availability through the API

Introduction

This tutorial will be an example of how you setup resource availability and request availability through the /availability endpoint, with the "available until booked" notion from the previous article in mind.
This tutorial will set up working hours for two employees and use general opening hours.

Setting up employees and their working hours

First we will define working hours for the two employees Marty and Doc. Marty works Mondays to Wednesdays and Doc works Thursdays and Fridays.

curl --request POST \
  --url https://api.timekit.io/v2/resources \
  --header 'Content-Type: application/json' \
  --user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
  --data '{
    "email": "[email protected]",
    "timezone": "America/Los_Angeles",
    "name": "Marty McFly",
    "password": "HoverBoard",
    "availability_constraints": [
    	{"allow_day": {"day":"Monday"}},
      {"allow_day": {"day":"Tuesday"}},
      {"allow_day": {"day":"Wednesday"}}
    ]
  }'
curl --request POST \
  --url https://api.timekit.io/v2/resources \
  --header 'Content-Type: application/json' \
  --user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
  --data '{
    "email": "[email protected]",
    "timezone": "America/Los_Angeles",
    "name": "Doc Brown",
    "password": "FluxCapacitator",
    "availability_constraints": [
    	{"allow_day": {"day":"Thursday"}},
      {"allow_day": {"day":"Friday"}}
    ]
  }'

We'll pretend that Marty gets the Id 7c0b9428-41f3-42cc-8ac4-f86c824eaa1f and Doc gets the Id e865df2c-3225-44f3-bb82-7c2e7ce6b360

Request availability.

Now we're ready to get some availability. We'll setup the request to /availability to define our opening-hours (9am-5pm). And we want to look for time-slots of 8 hours length in the next week. We don't prefer Marty over Doc as the resource that provides availability, so we'll just use the round-robin random mode.

curl --request POST \
  --url https://api.timekit.io/v2/availability \
  --header 'Content-Type: application/json' \
  --user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
  --data '{
    "mode": "roundrobin_random",
    "resources": [
    	"7c0b9428-41f3-42cc-8ac4-f86c824eaa1f",
      "e865df2c-3225-44f3-bb82-7c2e7ce6b360"
    ],
    "constraints": [
    	{"allow_hours": {"start": 9, "end": 17}},
      {"block_weekends": {} }
    ]
    "length": "2 hours",
    "from": "now",
    "to": "1 week"
  }'

As we defined the working hours on Marty and Doc, we really didn't have to define the "block_weekends" constraint here, but we hope it will clarify how you define your constraints.

The result

The result should look something like this:

{
  "data": [
    {
      "start": "2018-05-14T09:00:00-08:00",
      "end": "2018-05-14T17:00:00-08:00",
      "resources": [
        {
          "id": "7c0b9428-41f3-42cc-8ac4-f86c824eaa1f",
          "name": "Marty McFly",
          "timezone": "America\/Los_Angeles"
        }
      ]
    },
    {
      "start": "2018-05-15T09:00:00-08:00",
      "end": "2018-05-15T17:00:00-08:00",
      "resources": [
        {
          "id": "7c0b9428-41f3-42cc-8ac4-f86c824eaa1f",
          "name": "Marty McFly",
          "timezone": "America\/Los_Angeles"
        }
      ]
    },
    {
      "start": "2018-05-16T09:00:00-08:00",
      "end": "2018-05-16T17:00:00-08:00",
      "resources": [
        {
          "id": "7c0b9428-41f3-42cc-8ac4-f86c824eaa1f",
          "name": "Marty McFly",
          "timezone": "America\/Los_Angeles"
        }
      ]
    },
    {
      "start": "2018-05-17T09:00:00-08:00",
      "end": "2018-05-17T17:00:00-08:00",
      "resources": [
        {
          "id": "e865df2c-3225-44f3-bb82-7c2e7ce6b360",
          "name": "Doc Brown",
          "timezone": "America\/Los_Angeles"
        }
      ]
    },
    {
      "start": "2018-05-18T09:00:00-08:00",
      "end": "2018-05-18T17:00:00-08:00",
      "resources": [
        {
          "id": "e865df2c-3225-44f3-bb82-7c2e7ce6b360",
          "name": "Doc Brown",
          "timezone": "America\/Los_Angeles"
        }
      ]
    }
  ]
}

This concludes our initial tutorial on availability. Please refer to our API reference for more details