Create events on Google calendar using Google Calendar API in Node.js

Sudhanshu Sharma
2 min readNov 27, 2021

In this article, we will see how to create Google Calendar events with Node.js applications.

Use the Calendar API

Every request your application sends to Calendar API v3. needs an authorization token. This token also identifies the application for Google. The application must use the OAuth 2.0 to authorize requests — other authorization protocols are not supported.

  1. When creating the application, register it with the help of Google Calendar API Console. Google will provide you with a client ID and a client secret. You’ll need this information later.
  2. Activate the Google Calendar API in the API Console. If it isn’t listed there, skip this step.
  3. When your application requires access to user data, it asks Google for a particular scope of access.
  4. Then Google demonstrates a consent screen to the user, asking him to authorize your application to request some of their info.
  5. If the user grants approval, Google gives your application a short-lived access token.
  6. Then your application requests user data and attaches the token to the request.
  7. In case Google determines your request and token as valid, it returns the requested data.

Calendar API: examples

To begin with, create an index.js file in your project directory and paste the below code.

summary: Title of the event.

description: Description of the event. Can contain HTML. Optional.

reminders: reminder object has an attribute overrides which sends the user notifications at the specified minutes before the start of the event.

event.insert() method take three parameters.

  • calendarId: it’s the calendar identifier which can either be an email address of the calendar on which you are to create an event or a special keyword ‘primary’ that will use the primary calendar of the logged-in user.
  • event is the event to create with all the needed information such as start and end. The only two required fields here are the start and end times.
  • auth: google auth

let’s run the index.js file

If the request is successful an event will be created which will be visible in the user’s calendar dashboard.

CONCLUSION

We just successfully created an google event.
If you came thus far congrats, ✌.
Surely, you’ve got questions or issues as you went through this tutorial, kindly drop your comments and you’d be responded to ASAP.
Once again thanks for reading, Clap, and share!👌

--

--

Sudhanshu Sharma

Full Stack Developer, Happy to share whatever I learn. Get a friend link by messaging me Instagram: sudhanshu__coder Email: sudhanshusharma647@gmail.com 🇮🇳