gcal.googlecalendar.createevent
Home > @runlightyear/gcal > GoogleCalendar > createEvent
GoogleCalendar.createEvent() method
This API is in beta and may contain contain bugs. Can be used in production with caution.
Creates an event.
Signature:createEvent(props: CreateEventProps): Promise<CreateEventResponse>;
Parameters
Parameter | Type | Description |
---|---|---|
props | CreateEventProps |
Promise<CreateEventResponse>
Example 1
Create an event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addHours(date: Date, hours: number) {
return new Date(date.getTime() + hours * 60 * 60 * 1000);
}
defineAction({
name: "createEvent",
title: "Create Event",
apps: ["gcal"],
variables: ["calendarId?", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
dateTime: addHours(new Date(), 1).toISOString(),
},
end: {
dateTime: addHours(new Date(), 2).toISOString(),
},
},
});
console.log("Response: ", response.data);
},
});
Example 2
Create an event with attendees
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function addHours(date: Date, hours: number) {
return new Date(date.getTime() + hours * 60 * 60 * 1000);
}
defineAction({
name: "createEventWithAttendees",
title: "Create Event with Attendees",
apps: ["gcal"],
variables: ["calendarId?", "summary", "attendees"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const attendees = variables.attendees!.split(",");
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
dateTime: addHours(new Date(), 1).toISOString(),
},
end: {
dateTime: addHours(new Date(), 2).toISOString(),
},
attendees: attendees.map((email) => ({
email,
})),
},
});
console.log("Response: ", response.data);
},
});
Example 3
Create an all-day event
import { defineAction } from "@runlightyear/lightyear";
import { GoogleCalendar } from "@runlightyear/gcal";
function tomorrow() {
const date = new Date();
date.setDate(date.getDate() + 1);
return date.toISOString().split("T")[0];
}
defineAction({
name: "createAllDayEvent",
title: "Create All Day Event",
apps: ["gcal"],
variables: ["calendarId?", "summary"],
run: async ({ auths, variables }) => {
const gcal = new GoogleCalendar({
auth: auths.gcal,
});
const response = await gcal.createEvent({
calendarId: variables.calendarId || "primary",
event: {
summary: variables.summary!,
start: {
date: tomorrow(),
},
end: {
date: tomorrow(),
},
},
});
console.log("Response: ", response.data);
},
});