Only show these results:

Manage events with Ruby

This page explains how to use the Nylas Ruby SDK and Calendar API to create and manage events.

Before you begin

Before you start, you must have done the following tasks:

List calendars and events

To access the calendars associated with an end user's account, use the nylas.calendars object. You can access their default calendar and any custom calendars (for example, those that the end user created).

The following code sample shows how to retrieve five calendars from an end user's account.

For more information about calendars and their parameters, see the Calendar reference documentation.

To access the events associated with an end user's account, use the object.

The following example shows how to query the Nylas APIs to retrieve the next five events from an end user's calendar, starting at the time that you make the request.

You can fine-tune the results by setting certain parameters, like starts, to specify a time range, a maximum number of results, and any pagination settings.

For more information, see the Events reference documentation.

Create an event and send email notifications

The following code sample creates an event and assigns its title.

Keep the following things in mind when you create events:

  • You add participants in the participants array. Each requires an email value. You can also include a name.
  • Event times are set with UTC timestamps, and can be one of four sub-objects that correspond to their time and duration: time, timespan, date, or datespan.
  • The calendar_id must be the ID for a calendar that the end user has Write access to. For information on retrieving calendar IDs, see List calendars and events.

When you create an event, you can set variables that change its attributes, such as its title and location. For more information on available attributes, see the POST /v3/grants/{grant_id}/events reference documentation.

After you create the event, use events.update() to save it to the end user's calendar.

By default, Nylas sets notify_participants to false. This means that when you create an event, Nylas defaults to not sending email notifications. If you want to send notifications to participants, set notify_participants to true.

All together, the code to create an event and send email notifications resembles the following example.

Explore the Calendar API

If you've made it to this point, congratulations! You've learned how to manage events with the Nylas Ruby SDK and Calendar API! 🎉

There's plenty more that you can do with Nylas. Take a look at the following resources to learn more.