gcal.googlecalendar.listevents
Home > @runlightyear/gcal > GoogleCalendar > listEvents
GoogleCalendar.listEvents() method
This API is in beta and may contain contain bugs. Can be used in production with caution.
Returns events on the specified calendar.
Signature:listEvents(props: ListEventsProps): Promise<ListEventsResponse>;
Parameters
Parameter | Type | Description |
---|---|---|
props | ListEventsProps |
Promise<ListEventsResponse>
Example
List upcoming events
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addDays(date: Date, days: number) {
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
}
defineAction({
name: "listUpcomingEvents",
title: "List Upcoming Events",
apps: ["gcal"],
variables: ["calendarId?"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.listEvents({
calendarId: variables.calendarId || "primary",
timeMin: new Date().toISOString(),
timeMax: addDays(new Date(), 2).toISOString(),
});
console.log("Response: ", response.data);
},
});