Getting started with Nylas Scheduler
In this tutorial, you’ll learn how to install the Scheduler UI Components and set up Nylas Scheduler.
Before you begin
Before you start using the Scheduler UI Components, complete the following tasks:
- Sign up for a Nylas account.
- Sign in to the v3 Dashboard and create a Nylas application.
- Generate an API key for your application and save it.
- Authenticate an end user grant.
Install Scheduler UI Components
There are two ways to add Scheduler: using Web components (HTML/Vanilla JS) or React.
- To use the Scheduler UI Component as Web components, include the CDN package links in your project.
- To install the Scheduler UI Components as React components, install the npm package. The npm package includes both the Scheduling Component and the Scheduler Editor Component.
{/*Scheduling Component*/}https://cdn.jsdelivr.net/npm/@nylas/web-elements@latest/dist/cdn/nylas-scheduling/nylas-scheduling.es.js
{/*Scheduler Editor Component*/}https://cdn.jsdelivr.net/npm/@nylas/web-elements@latest/dist/cdn/nylas-scheduler-editor/nylas-scheduler-editor.es.jsnpm install @nylas/react@latestUse Scheduler UI Components in your project
The following examples show how you can include the Scheduling Component in your project.
<html> <body> <nylas-scheduling></nylas-scheduling>
<script type="module">
import { defineCustomElement } from "https://cdn.jsdelivr.net/npm/@nylas/web-elements@latest/dist/cdn/nylas-scheduling/nylas-scheduling.es.js";
defineCustomElement();
const nylasScheduling = document.querySelector('nylas-scheduling');
// Set the scheduler configuration ID if using public configuration (`requires_session_auth=false`) nylasScheduling.configurationId = '<SCHEDULER_CONFIG_ID>';
// OR, Set the scheduler session ID if using private configuration (`requires_session_auth=true`) // nylasScheduling.sessionId = '<SCHEDULER_SESSION_ID>'; </script> </body></html>import React from 'react';import { NylasScheduling } from '@nylas/react';
function App() { // Set the scheduler configuration ID if using public configuration (`requires_session_auth=false`) const configId = '<SCHEDULER_CONFIG_ID>'; return <NylasScheduling configurationId={configId} />;
// OR, Set the scheduler session ID if using private configuration (`requires_session_auth=true`) // const sessionId = '<SCHEDULER_SESSION_ID>'; // return <NylasScheduling sessionId={sessionId} />;}
export default App;For more information, see the Scheduler UI Components reference documentation.
Create a configuration
Next, create a configuration for your first event. A configuration defines your preferred event settings and preferences. Nylas Scheduler stores Configuration objects in the Scheduler database, and loads them as Scheduling Pages in the Scheduler UI.
You can create a configuration either using the Scheduler API or using the Scheduler Editor.
Create a configuration using the Scheduler API
You can make a POST /v3/grants/<NYLAS_GRANT_ID>/scheduling/configurations request to create a configuration.
By default, Nylas creates a public configuration that doesn’t require a session. See Scheduler configurations for more information.
The response includes the ID of the Configuration object.
!!!include(v3_code_samples/scheduler/configurations/POST/curl.sh)!!!{ "ID": "AAAA-BBBB-1111-2222", "participants": [ { "name": "Nylas", "email": "nylas@example.com", "is_organizer": true, "availability": { "calendar_ids": [ "primary" ]}, "booking": { "calendar_id": "primary" }}], "availability": { "duration_minutes": 30 }, "event_booking": { "title": "My test event" }}Create a configuration using the Scheduler Editor
When you create a Scheduling Page using the Scheduler Editor in the UI, Nylas creates a corresponding configuration.
To create a configuration using the Scheduler Editor, follow these steps:
-
To use the Scheduler UI Components, include the Scheduler Editor and Scheduling scripts in your app.
- Set
nylasSessionsConfig. The Scheduler Editor Component uses the Hosted authentication details innylasSessionsConfigto interact with the Nylas APIs. For more information on the required properties and other authentication options, see Set up the Scheduler Editor Component. - By default, Nylas creates a public configuration that doesn’t require a session (
requires_session_auth: false). For more information, see Scheduler configurations.
The following examples add the Nylas Scheduler Editor and Scheduling scripts, and create a public configuration. The React example includes both Scheduler Editor and the Scheduling Page scripts in one file.
- Set
!!!include(v3_code_samples/scheduler/quickstart-scheduler-editor.html" />!!!include(v3_code_samples/scheduler/quickstart-scheduling.html" />!!!include(v3_code_samples/scheduler/quickstart-scheduler-editor-scheduling-app.tsx)!!!!!!include(v3_code_samples/scheduler/quickstart-scheduler-editor-index.css)!!!!!!include(v3_code_samples/scheduler/quickstart-scheduling-app.css)!!!-
In the UI, create a Scheduling Page from the Scheduler Editor. Creating a Scheduling Page creates a corresponding configuration.
- The examples in the previous step create a public configuration.
- The Scheduling Page’s URL includes the configuration ID.
- You can also make a
GET /v3/grants/<NYLAS_GRANT_ID>/scheduling/configurationsrequest to retrieve the configuration ID.
(Optional) Create a session
Next, create a session by making a POST /v3/scheduling/sessions request. When you create a session, you must include the Configuration object ID that you generated in the previous step. Nylas recommends you set a Time-to-Live (TTL) value for each session, and refresh the sessions as they expire.
The response includes the ID of the session.
!!!include(v3_code_samples/scheduler/sessions/POST/curl.sh)!!!{ "request_id": "5fa64c92-e840-4357-86b9-2aa364d35b88", "data": { "session_id": "XXXX-YYYY-1111-2222" }}Set up the Scheduler UI Components
Set up the Scheduler Editor Component
To modify the configuration in the UI, you can set up the Scheduler Editor component.
Set the nylasSessionsConfig property. The Scheduler Editor Component uses the Hosted authentication details in nylasSessionsConfig to interact with the Nylas APIs.
| Property | Description |
|---|---|
clientId | The client ID from the Nylas Dashboard. |
redirectUri | The URL that the OAuth provider sends end users back to after they authenticate. |
domain | The Nylas authentication domain. For the U.S. data center, use https://api.us.nylas.com/v3. For the E.U. data center, use https://api.eu.nylas.com/v3. |
hosted | Whether to redirect end users to the hosted login component. |
accessType | Whether Nylas should return a refresh token along with the exchange token. |
!!!include(v3_code_samples/scheduler/scheduler-editor-api-config.html" />!!!include(v3_code_samples/scheduler/scheduler-editor-api-config.tsx)!!!Set up the Scheduling Component
The Scheduling Component requires either a sessionId (private configuration) or a configurationId (public configuration) to load the Scheduling Page with the associated configuration.
By default, the Scheduling Component renders all of its sub-components (mode="app"). If nothing is configured in the app mode, Scheduler follows the standard booking flow. See Using the Scheduling Component for more information about configuration modes.
!!!include(v3_code_samples/scheduler/scheduling-api-config.html" />!!!include(v3_code_samples/scheduler/scheduling-api-config.tsx)!!!Set up rescheduling and cancelling options
Booking confirmations and email notifications can include buttons that allow the participant to reschedule or cancel the booking. If they click one of the buttons, they’re redirected to the corresponding page where they can make changes to their booking.
To set up the rescheduling and cancelling options, you need to create the rescheduling and cancellation pages, then add the URLs to the configuration.
Create rescheduling and cancellation pages
Before you can include the option to reschedule or cancel a booking, you must create corresponding pages and set up their URLs.
To create a page to reschedule an existing booking, add the rescheduleBookingRef property to the Scheduling Component and set it to the booking reference that you want to update.
To create a page to cancel an existing booking, include the cancelBookingRef property to the Scheduling Component and set it to the booking reference that you want to cancel.
!!!include(v3_code_samples/scheduler/rescheduling.tsx)!!!!!!include(v3_code_samples/scheduler/cancellation.tsx)!!!Add URLs to the configuration
You can add the URLs to the configuration either using the Scheduler API or modifying the Scheduler Editor Component.
Add URLs to configuration using the Scheduler API
To update the configuration, make a PUT /v3/grants/<NYLAS_GRANT_ID>/scheduling/configurations/<SCHEDULER_CONFIG_ID> request with scheduler.rescheduling_url and scheduler.cancelling_url.
!!!include(v3_code_samples/scheduler/configurations-id/PUT/curl.sh)!!!{ "ID": "AAAA-BBBB-1111-2222", "participants": [ { "name": "Nylas", "email": "nylas@example.com", "is_organizer": true, "availability": { "calendar_ids": [ "primary" ]}, "booking": { "calendar_id": "primary" }}], "availability": { "duration_minutes": 30 }, "event_booking": { "title": "My test event" }, "scheduler": { "rescheduling_url": "https://www.example.com/reschduling/:booking_ref", "cancellation_url": "https://www.example.com/cancelling/:booking_ref" }}Modify the Scheduler Editor Component
To update the configuration in the Scheduler Editor Component, set the rescheduling_url and cancelling_url parameters. These should correspond with the URLs of the rescheduling and cancelling pages you created.
!!!include(v3_code_samples/scheduler/scheduler-editor-reschedule-cancel.html" />!!!include(v3_code_samples/scheduler/scheduler-editor-reschedule-cancel.tsx)!!!(Optional) Change your Scheduling Page name
By default, Scheduling Pages use the organizer’s user name as the Page name, which Nylas displays in the top-left corner of the calendar view. You can change the Page name on the Event info tab.
(Optional) Style components using CSS shadow parts
The Scheduler UI Components support CSS shadow parts (::part()) for a higher level of UI customization. CSS shadow parts allow you to style certain parts of a web component without having to modify its internal structure or styles directly. For more information on available shadow parts, see the Scheduler UI Components reference documentation.
The following CSS sets the background and foreground colors for a component on the Scheduling Page.
/* Your stylesheet */nylas-scheduling::part(ndp__date--selected) { background-color: #2563EB; color: #FFFFFF;}
(Optional) Disable confirmation emails
By default, Nylas sends a confirmation email to all attendees when a booking is created, rescheduled, or cancelled. To disable confirmation emails, set disable_emails to true in the configuration.
What’s next?
Now that you’re set up with the Nylas Scheduler, check out the following documentation for more information:
- The Scheduler UI Components references and Scheduler API references.
- How to use the Scheduler API.
- How to use the Scheduling Component and the Scheduler Editor Component.