Skip to main content

Actions

The ballerinax/googleapis.calendar package exposes the following clients:

ClientPurpose
ClientManages calendars and events through the Google Calendar API V3.

Client

Manages calendars and events through the Google Calendar API V3.

Configuration

FieldTypeDefaultDescription
authBearerTokenConfig|OAuth2RefreshTokenGrantConfig|JwtIssuerConfigRequiredAuthentication configuration: typically OAuth 2.0 refresh token credentials.
secureSocketConfigClientSecureSocket()SSL/TLS configuration for secure connections.

Initializing the client

import ballerinax/googleapis.calendar;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string refreshUrl = ?;

calendar:Client calendarClient = check new ({
auth: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
});

Operations

Calendar operations

getCalendars

Retrieves all calendars accessible to the authenticated user as a stream.

Parameters:

NameTypeRequiredDescription
optionalCalendarsToAccess?NoRecord containing optional parameters such as minAccessRole, showDeleted, and showHidden.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: stream<Calendar, error?>|error

Sample code:

stream<calendar:Calendar, error?> calendars = check calendarClient->getCalendars();
check from calendar:Calendar cal in calendars
do {
// process each calendar
};

Sample response:

{
"kind": "calendar#calendarListEntry",
"etag": "\"abc123\"",
"id": "primary",
"summary": "[email protected]",
"timeZone": "America/New_York",
"colorId": "14",
"backgroundColor": "#9FE1E7",
"foregroundColor": "#000000",
"accessRole": "owner",
"defaultReminders": [],
"conferenceProperties": {
"allowedConferenceSolutionTypes": ["hangoutsMeet"]
},
"primary": true
}
createCalendar

Creates a new secondary calendar.

Parameters:

NameTypeRequiredDescription
titlestringYesThe name/summary for the new calendar.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: CalendarResource|error

Sample code:

calendar:CalendarResource newCalendar = check calendarClient->createCalendar("Project Meetings");

Sample response:

{
"kind": "calendar#calendar",
"etag": "\"def456\"",
"id": "[email protected]",
"summary": "Project Meetings",
"timeZone": "UTC",
"conferenceProperties": {
"allowedConferenceSolutionTypes": ["hangoutsMeet"]
}
}
deleteCalendar

Deletes a secondary calendar. Use "primary" to clear (not delete) the primary calendar.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesThe calendar identifier to delete.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: error?

Sample code:

check calendarClient->deleteCalendar("[email protected]");

Event operations

createEvent

Creates a new event in the specified calendar.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier (use "primary" for the primary calendar).
eventInputEventYesRecord containing event information such as summary, start/end times, attendees, and reminders.
optionalEventsToAccess?NoRecord containing optional query parameters like conferenceDataVersion, maxAttendees, sendUpdates, and supportsAttachments.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: Event|error

Sample code:

calendar:Event event = check calendarClient->createEvent("primary", {
summary: "Project Kickoff Meeting",
'start: {
dateTime: "2024-03-20T10:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2024-03-20T11:00:00+00:00",
timeZone: "UTC"
},
attendees: [
{ email: "[email protected]" }
],
reminders: {
useDefault: false,
overrides: [
{ method: "popup", minutes: 15 },
{ method: "email", minutes: 30 }
]
}
});

Sample response:

{
"kind": "calendar#event",
"etag": "\"ghi789\"",
"id": "evt123abc",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=ZXZ0MTIz",
"created": "2024-03-15T08:00:00.000Z",
"updated": "2024-03-15T08:00:00.000Z",
"summary": "Project Kickoff Meeting",
"creator": {
"email": "[email protected]",
"self": true
},
"organizer": {
"email": "[email protected]",
"self": true
},
"start": {
"dateTime": "2024-03-20T10:00:00Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2024-03-20T11:00:00Z",
"timeZone": "UTC"
},
"attendees": [
{
"email": "[email protected]",
"responseStatus": "needsAction"
}
],
"reminders": {
"useDefault": false,
"overrides": [
{ "method": "popup", "minutes": 15 },
{ "method": "email", "minutes": 30 }
]
}
}
quickAddEvent

Creates an event at the moment with simple text, letting Google parse the date, time, and title automatically.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier (use "primary" for the primary calendar).
textstringYesThe text describing the event to be created (e.g., "Team lunch at noon tomorrow").
sendUpdatesstring?NoConfiguration for notifying about the creation. Possible values: "all", "externalOnly", "none".
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: Event|error

Sample code:

calendar:Event quickEvent = check calendarClient->quickAddEvent("primary", "Team standup at 9am tomorrow");

Sample response:

{
"kind": "calendar#event",
"etag": "\"jkl012\"",
"id": "evt456def",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=ZXZ0NDU2",
"created": "2024-03-15T09:00:00.000Z",
"updated": "2024-03-15T09:00:00.000Z",
"summary": "Team standup",
"start": {
"dateTime": "2024-03-16T09:00:00Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2024-03-16T09:30:00Z",
"timeZone": "UTC"
}
}
getEvent

Retrieves a single event by its ID from the specified calendar.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier.
eventIdstringYesThe event identifier.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: Event|error

Sample code:

calendar:Event event = check calendarClient->getEvent("primary", "evt123abc");

Sample response:

{
"kind": "calendar#event",
"etag": "\"mno345\"",
"id": "evt123abc",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=ZXZ0MTIz",
"summary": "Project Kickoff Meeting",
"start": {
"dateTime": "2024-03-20T10:00:00Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2024-03-20T11:00:00Z",
"timeZone": "UTC"
}
}
updateEvent

Updates an existing event in the specified calendar.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier.
eventIdstringYesThe event identifier.
eventInputEventYesRecord containing the updated event information.
optionalEventsToAccess?NoRecord containing optional query parameters.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: Event|error

Sample code:

calendar:Event updatedEvent = check calendarClient->updateEvent("primary", "evt123abc", {
summary: "Project Kickoff Meeting (Updated)",
'start: {
dateTime: "2024-03-20T10:00:00+00:00",
timeZone: "UTC"
},
end: {
dateTime: "2024-03-20T12:00:00+00:00",
timeZone: "UTC"
},
location: "Conference Room A",
description: "Updated: extended to 2 hours"
});

Sample response:

{
"kind": "calendar#event",
"etag": "\"pqr678\"",
"id": "evt123abc",
"status": "confirmed",
"summary": "Project Kickoff Meeting (Updated)",
"location": "Conference Room A",
"description": "Updated: extended to 2 hours",
"start": {
"dateTime": "2024-03-20T10:00:00Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2024-03-20T12:00:00Z",
"timeZone": "UTC"
}
}
deleteEvent

Deletes an event from the specified calendar.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier.
eventIdstringYesThe event identifier.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: error?

Sample code:

check calendarClient->deleteEvent("primary", "evt123abc");

Event queries

getEvents

Retrieves all events from a calendar as a stream, with optional filtering criteria.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier.
filterEventFilterCriteria?NoRecord containing filtering criteria such as timeMin, timeMax, q (search text), orderBy, singleEvents, and more.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: stream<Event, error?>|error

Sample code:

stream<calendar:Event, error?> events = check calendarClient->getEvents("primary", {
timeMin: "2024-03-01T00:00:00Z",
timeMax: "2024-03-31T23:59:59Z",
singleEvents: true,
orderBy: calendar:START_TIME
});
check from calendar:Event evt in events
do {
// process each event
};

Sample response:

{
"kind": "calendar#event",
"etag": "\"stu901\"",
"id": "evt789ghi",
"status": "confirmed",
"summary": "Weekly Standup",
"start": {
"dateTime": "2024-03-04T09:00:00Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2024-03-04T09:30:00Z",
"timeZone": "UTC"
},
"recurrence": ["RRULE:FREQ=WEEKLY;BYDAY=MO"]
}
getEventsResponse

Retrieves events with full pagination support, returning an EventResponse record that includes sync tokens and page tokens for incremental synchronization.

Parameters:

NameTypeRequiredDescription
calendarIdstringYesCalendar identifier.
countint?NoNumber of events required in one page.
pageTokenstring?NoToken for retrieving the next page of results.
syncTokenstring?NoToken for getting incremental sync (only changes since the last sync).
filterEventFilterCriteria?NoRecord containing filtering criteria.
userAccountstring?NoThe email address of the user for requesting delegated access in service account.

Returns: EventResponse|error

Sample code:

calendar:EventResponse response = check calendarClient->getEventsResponse("primary", count = 10);

Sample response:

{
"kind": "calendar#events",
"etag": "\"vwx234\"",
"summary": "[email protected]",
"updated": "2024-03-15T10:00:00.000Z",
"timeZone": "UTC",
"accessRole": "owner",
"nextSyncToken": "CLDd7YGy9IcDELDd7YGy9IcDGAUggL3e",
"items": [
{
"kind": "calendar#event",
"id": "evt789ghi",
"status": "confirmed",
"summary": "Weekly Standup",
"start": {
"dateTime": "2024-03-04T09:00:00Z"
},
"end": {
"dateTime": "2024-03-04T09:30:00Z"
}
}
]
}