# Scheduling API for 1-to-1 bookings

In the previous guide, you learned how to use our API to set up a new booking page.

This guide will teach you how to completely dispense with the Vyte interface and fully manage 1-1 bookings using only the API.

To sum up, we will explore how to use the API to create a new booking request for a user, that means that we will learn how to retrieve the available slots for a user, then how to create a new booking request and finally, how to update the created event.

# Get the available slots for a user

# Using the API

When someone wants an appointment with a user, the first thing we have to do is to retrieve when this user is available (to draw a parallel with the Vyte Page, we want to retrieve what is shown in the slot picker).

To achieve this, we will use the Slots API. We will perform a GET request to the /v2/slots endpoint. Here is a little reminder of the available query params :

Query parameters

  • duration number required

    Duration of the appointment in minutes.

  • emails string required you need either emails or user_ids

    Email(s) of people that already have a Vyte account and with whom you want to book an appointment. If several emails are provided, they must be separated with a comma and and the API returns the slots at which all users are available.

  • users string required you need either emails or user_ids

    List of user_id you want to book an appointment with. If several user_id are provided, they must be separated with a comma and and the API returns the slots at which all users are available.

  • from string required

    Date from when you want to get available slots (included) formatted as YYYY-MM-DD.

  • to string required

    Date until when you want to get available slots (included) formatted as YYYY-MM-DD.

  • timezone string

    The timezone expressed according to TZ database name.

In the rest of this guide, we will assume that someone wants to make a 1 hour meeting on September 1 or 2 with our user John Doe whose id is : 5f3feb7821046c3bb9327e6a.

So, to retrieve the availabilities of our user for these days, we make the following request :

curl --request GET 'https://api.vyte.in/v2/slots?duration=60&users=5f3feb7821046c3bb9327e6a&from=2020-10-01&to=2020-10-02' \
--header 'Authorization: 2lnpjjrurrl49xja5oo0qujtl60embr7zppiphc5fcav4n7ycx' \

We get the following response :

{
  "timezone": "Europe/Paris",
  "from": "2020-10-01",
  "to": "2020-10-02",
  "slots": [
    {
      "start": {
        "dateTime": "2020-10-01T00:00:00+02:00"
      },
      "end": {
        "dateTime": "2020-10-01T01:00:00+02:00"
      }
    },
    {
      "start": {
        "dateTime": "2020-10-01T01:00:00+02:00"
      },
      "end": {
        "dateTime": "2020-10-01T02:00:00+02:00"
      }
    },
    {
      "start": {
        "dateTime": "2020-10-01T02:00:00+02:00"
      },
      "end": {
        "dateTime": "2020-10-01T03:00:00+02:00"
      }
    },
    {
      "start": {
        "dateTime": "2020-10-01T03:00:00+02:00"
      },
      "end": {
        "dateTime": "2020-10-01T04:00:00+02:00"
      }
    },
    ...
  ]
}

Remember that you can also retrieve these slots grouped by day by making the request to /v2/slots/days instead of /v2/slots.

Now that we have all the available slots for our user John Doe, we can make our other user choose a slot that works for them. You may also want to use some algorithm or conditions on your end to automatically determine which one is the best.

We will consider here that September 2 from 10:00 to 11:00 a.m. is a good choice.

# (Optional) Using our web component

We provide a useful slot picker as a Vue.js component to easily let your users choose a slot. For more information, please check this guide.

# Create a new event

Let's create a new meeting request to John Doe for the chosen date. To achieve this, we have to create a new event using the Events API.

So, we will do this by making this POST request :

curl --request POST 'https://api.vyte.in/v2/events' \
--header 'Authorization: 2lnpjjrurrl49xja5oo0qujtl60embr7zppiphc5fcav4n7ycx' \
--header 'Content-Type: application/json' \
--data-raw '{
  "title": "Meeting with Quentin Tarantino",
  "created_by": {
    "user": "5f3feb7821046c3bb9327e6a"
  },
  "dates": [
    {
      "all_day": false,
      "date": "2020-09-02T10:00:00",
      "end_date": "2020-09-02T11:00:00"
    }
  ],
  "invitees": {
    "full_name": "Quentin Tarantino",
    "email": "quentin.tarantino@hollywood.com"
  },
  "places": [
    {
      "name": "Place for the meeting."
    }
  ],
  "vyteme": true
}'

Note that it's important for this use case to set the param vyteme to true. If you need more information, please refere to this part.

Congrats 👏
We created our first booking request by using only the API.

# Confirm or cancel the event

The last step in this workflow is to confirm (or cancel) the meeting as soon as our user John Doe is okay.

Nothing complicated for this. We just have to send a GET request at /v2/events/:event_id/confirm (or /v2/events/:event_id/cancel) :

curl --request POST 'https://api.vyte.in/v2/events/5f43a0caf795d9206556122a/confirm' \
--header 'Authorization: 2lnpjjrurrl49xja5oo0qujtl60embr7zppiphc5fcav4n7ycx' \

Here we are ! We successed to manage a new booking request from end-to-end only with the API.