Get started with Rowy in minutes
The average worker spends at least 3 hours a week in meetings, and 30% of all workers report 5 hours or more! Meetings are a necessity in any organization, but they can also be time-consuming and unproductive if not prepared properly efficiently. This is why a tool like Google Calendar has become so important in today's business environment to schedule and manage meetings.
In this article, we'll learn how to use Google Calendar's API to take things a level higher with custom features for your business.
There are 3 main use cases for using Google Calendar's API:
After creating a new Rowy project, enable the Google Calendar API in your Google Cloud console:
Because Rowy is built on top of Google Cloud Functions, you don't need to worry about setting up OAuth2 via service accounts. Rowy directly integrates with Google Auth, so you can create an API client for Google Calendar in just a few lines of code:
const calendar = require('@googleapis/calendar')
const gauth = new calendar.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/calendar']
});
const authClient = await gauth.getClient();
const client = await calendar.calendar({
version: 'v3',
auth: authClient
});
The API scope /auth/calendar
will allow you to have read and write accesses to all your calendars, events, and tasks.
Now that we have an API client, we can retrieve events from our calendars. The following code will retrieve the next 10 events from your primary calendar:
const events = await client.events.list({
calendarId: 'primary',
timeMin: new Date().toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime',
}).then(res => res.data.items)
events.map((event, i) => {
const start = event.start.dateTime || event.start.date;
console.log(`${start} - ${event.summary}`);
})
In a new Rowy table, you can create a webhook to run this code from an API request without having to set up and maintain a web server:
You can then use the Firebase collection reference available in all Rowy webhook to import the events you just read as new rows in your Rowy table:
ref = db.collection('events')
ref.add({
start: event.start,
summary: event.summary
})
With Rowy, you can easily run custom scripts to call any third party API to interact with your data. One interesting use case for Google Calendar's API is to send email reminders before events happen.
One way to do this is to use the Sendgrid API to send emails programmatically. For example, you can create a Rowy Action column to send an email reminder whenever you click on the button:
It only takes a couple lines of code to send an email with Sendgrid from the Action column's settings:
const action: Action = async ({ row }) => {
await fetch("https://api.sendgrid.com/v3/mail/send", {
...
})
}
If you want to learn more about managing emails with Sendgrid, check out our Sendgrid API tutorial.
Naturally, you can also use the Google Calendar API to create and update events from Rowy, using another Action column for example:
var event = {
'summary': 'Google I/O 2015',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': '2015-05-28T09:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'end': {
'dateTime': '2015-05-28T17:00:00-07:00',
'timeZone': 'America/Los_Angeles',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'},
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
},
};
await client.events.insert({
calendarId: 'primary',
resource: event
})
This is particularly useful to sync third-party tools with Google Calendar to centralize all your appointments in a single source of truth.
That's a wrap! Hope this article helped you clear out how to create and read events using Google Calendar's API.
Note that this API offers many more features than what we covered in this article: you can also manage entire calendars, access Google Meet data, or even create a Calendly clone! Feel free to check out more of our demos to get your creative juices flowing.
If you have any questions, feel free to join our community on Discord. We're happy to provide assistance with Rowy!