-
Notifications
You must be signed in to change notification settings - Fork 11
Setup Instructions🔰
Head to the Notion integration site and create a new integration. You may name it whatever you'd like, just make sure that you select the correct associated workspace and give the integration full content capabilities. Comment capabilities are not required. Afterwards, you can simply submit. Keep your integration as an internal integration. Save your internal integration token for use later in the setup process. For your own security and safety, make sure you do not share this token with others!
Use a full-page database, not an inline one. The Notion API seems to dislike inline databases. You can still embed the database as a view in other pages, the root database just can't be inline. If you intend on deviating from the default property names and plan to modify them, take note of the script constants? that refer to the different properties.
Set up your database with the following properties. You may add additional properties or reorder them, but the ones shown in the table below are required.
Default Property Name | Property Type | Editability | Script Constant |
---|---|---|---|
Name | Title | ✅ Editable | NAME_NOTION |
Date | Date | ✅ Editable | DATE_NOTION |
Tags | Multi-select | TAGS_NOTION |
|
Calendar | Select | CALENDAR_NAME_NOTION |
|
Location | Text | ✅ Editable | LOCATION_NOTION |
Description | Text | ✅ Editable | DESCRIPTION_NOTION |
Event ID | Text | 🚫 Do Not Edit | EVENT_ID_NOTION |
Calendar ID | Select | 🚫 Do Not Edit | CALENDAR_ID_NOTION |
Last Sync | Date | 🚫 Do Not Edit | LAST_SYNC_NOTION |
Alternative database table that may be easier to interpret.
Default Property Name | Name | Date | Tags | Calendar | Location | Description | Event ID | Calendar ID | Last Sync |
---|---|---|---|---|---|---|---|---|---|
Property Type | Title | Date | Multi-select | Select | Text | Text | Text | Select | Date |
Editability | ✅ Editable | ✅ Editable | ✅ Editable | ✅ Editable | 🚫 Do Not Edit | 🚫 Do Not Edit | 🚫 Do Not Edit | ||
Script Constant | NAME_NOTION |
DATE_NOTION |
TAGS_NOTION |
CALENDAR_NAME_NOTION |
LOCATION_NOTION |
DESCRIPTION_NOTION |
EVENT_ID_NOTION |
CALENDAR_ID_NOTION |
LAST_SYNC_NOTION |
The listed property names are the default names. You may change them, but these modifications need to also be applied to the constants? at the top of the script. See the extra customization wiki page for more info on how to do this.
🚫 Do not edit the values for Event ID, Calendar ID, or Last Sync. These properties are used by the script to save vital information. You may hide these properties in the database view.
✅ The user can modify Name, Date, and Description property values freely.
The script constants entry of the table is just a reference for the name of the constants defined at the top of the script? that correspond to each property/tag. Don't worry about them if you do not plan on changing the default behavior or deviating from the default property/tag names. See the extra customization page for more info.
There are a few tags you may wish to set up to have access to several features such as deletion of events through Notion and **ignoring specific Notion event entries when synchronizing. **They are not strictly necessary for the script to function correctly but are nice to have. Do note that if you do not wish to use some or any of these tag features DO NOT USE THE RESERVED TAG NAMES. You may have some nasty unexpected behavior if you accidentally use a tag with a reserved name.
Optional tag features
These tags should be registered to the Tags multi-select property. You don't need to apply them to anything for now. These steps are just for setting them up so you may use them in the future. The color of the tags is entirely up to you and can be modified without changes in the script.
Default Tag Name | Script Constant | Corresponding Feature |
---|---|---|
Cancelled/Removed | CANCELLED_TAG_NAME |
Deletion of the event from both the Notion Database and GCal. The database entry in Notion will be archived (assuming you have ARCHIVE_CANCELLED_EVENTS enabled) and the corresponding GCal event will be removed. |
Ignore Sync | IGNORE_SYNC_TAG_NAME |
Makes it so that the script will ignore the event when synchronizing from Notion to GCal. It will not try to create a new event in GCal corresponding to that database entry, and it will also not try to update a GCal event that matches the Notion entry with information present in the Notion database entry. |
Connect your database with the Notion Integration you set up earlier! On the top right corner of Notion, you should see a button labeled with three dots. Click on it, then Add Connections at the bottom of the popup. Search for the integration you made earlier and select it!
Go to Google Apps Scripts and create a new project.
Once you've opened your new project, you should be on the editor page. If not, go to the editor page by clicking the button on the left-hand side that looks like < >
labeled editor. You should notice that you are in a new file named Code.gs
. Copy the contents of main.js
from this GitHub repository into this file, replacing everything already in it. If you'd like, you can rename this file by hovering over the file name, clicking the three dots that appear, and then Rename
. Naming the files is not required but is recommended!
Next, create a new script in your project. Click the big plus sign next to Files
and then script. You can name this file whatever you'd like but the wiki will refer to this file as calendarIds
. Copy the contents of the calendarIds
from this GitHub repository into that newly created file in your project, replacing everything.
In the editor view which you should still be in currently, click the plus button next to Services. Then, in the popup, set the identifier field to Calendar
or just search for the Google Calendar API service. Then go ahead and click add on the popup and the calendar service should be added to the project.
Now it's time to "tell" your script your Notion Integration key and what Notion Database the script should interface with!
Go into your project settings within Apps Script by clicking the cogwheel icon on the left side of the screen.
At the bottom, you will see a Script Properties section with the button Edit script properties. Click this once. Then click the button Add script property twice. Two new lines of text fields should show up.
Now to set up the database ID. Set one of the Property fields to DATABASE_ID
and set its corresponding Value to the LINK/URL of the database that you wish to use. There is no need to extract the database ID itself from the link.
Next, we'll add the Notion integration token. Set the Property field to NOTION_TOKEN
. Set its corresponding Value to the Notion Internal Integration Token we got from earlier. If you have multiple integrations for some reason, this must be the integration you shared the database with.
Click the Save script properties button once you're all done to save!
By default, the script will only sync with your primary google calendar. If you wish to add more, or ignore the primary calendar, you will need to modify the calendarIds.js file. You will need to add the calendar's ID as well as an arbitrary name you want to call it. Note that the name you assign to a given calendar ID must be unique!
You can find your calendar ID by going to your calendar's settings and going to the Integrate Calendar section. The ID is the one labeled Calendar ID and will look something like [email protected]
. Note that this process shouldn't be required for your primary calendar. By default, the calendarIds.js file is already set up to handle that by using the primary keyword.
Triggers is an Apps Script feature that allows for the script to be ran automatically based on a variety of events. Triggers can be set to activate at a certain time, every x amount of time, whenever your Google Calendar is updated, and more!
Click the clock icon on the left side of the screen to get to the triggers page. Then add a trigger with settings of your choosing. The function to be run should be set to main
You can have multiple triggers. It is recommended that you have one based on a time interval of your choosing, and another based on your Google calendars being updated.
To set up the calendar update trigger, set the event source to be From calendar
and fill out the owner email field.
To set up interval-based triggers, set the event source to Time-driven
. Pick anything you'd like for the type of time based trigger and the interval though a good balance between avoiding getting rate-limited and having timely updates is 15 or 30 minutes.
For any trigger you can set the failure notification setting to be whatever you'd like it to be. It is just the frequency at which Google will email you if a trigger execution of the script failed. You can even set up multiple failure notification settings for a trigger by clicking the plus sign. It is best to not have the notification be set to immediate or be too frequent. In a failure scenario where you can't really do anything but wait such as if the Notion servers go down, you might end up getting spammed with email notifications about your trigger failing.
Once you get to this point in the process, you should be all done with the setup! It is recommended that you manually trigger the script once though so you can give your script access to GCal. Go back to the main script by clicking the button on the left-hand side that looks like < >
labeled editor. Then make sure that the script being shown is the big main one. Select your main script on the left side of the editor if you are not on it already. Then, ensure that the drop down menu next to the Run and Debug buttons is set to main
. Then, you can click Run or Debug to run the script!
On your first run, the script will ask you to give access to GCal. A popup should come up asking you to sign in, give access, and all that. Do as told and allow the script to access GCal.
Congratulations! The script setup is complete. If you run into any issues, please first check out the FAQ and Common Errors section of the wiki before creating an issue, but don't hesitate to open an issue if you do have any trouble. If you're adventurous, check out some of the extra customization options. Star and watch the repository and look out for any updates to the script that may include bug fixes or additional features.