Skip to content

Manage events with Node.js

const now = Math.floor(Date.now() / 1000); // Time in Unix timestamp format (in seconds)
async function createAnEvent() {
try {
const event = await nylas.events.create({
identifier: "<NYLAS_GRANT_ID>",
requestBody: {
title: "Build With Nylas",
when: {
startTime: now,
endTime: now + 3600,
participants: [{ email: "[email protected]", name: "My Friend" }],
},
},
queryParams: {
calendarId: "<CALENDAR_ID>",
notifyParticipants: true,
},
});
console.log("Event:", event);
} catch (error) {
console.error("Error creating event:", error);
}
}
createAnEvent();

RSVP to an event

The following code sample replies “Yes” to an event.

async function sendEventRSVP() {
try {
const event = await nylas.events.update({
identifier: "<NYLAS_GRANT_ID>",
eventId: "<EVENT_ID>",
requestBody: {
participants: [
{
name: "Nylas DevRel",
status: "yes",
},
],
},
queryParams: {
calendarId: "<CALENDAR_ID>",
},
});
console.log("Event RSVP:", event);
} catch (error) {
console.error("Error to RSVP participant for event:", error);
}
}
sendEventRSVP();

For more information, see the Send RSVP references.