Zapier is essential to architecting a cohesive and streamlined system with Notion. It powers automations an integrations with other apps. But a persisting limitation is Zapier’s inability to update Relation
properties. As a workaround, we can directly access the Notion API with the Code by Zapier action.
Let’s walk through the configuration with a hypothetical scenario. Members of Notion A-to-Z enjoy access to the functional demos and Zap template. If you’ve yet to join, we’d love to have you onboard.
For this tutorial, you’ll want to have an existing Zapier account and basic familiarity with Zaps, including the Webhooks by Zapier trigger.
As a framework for our configuration, imagine…
Title
propertyRelation
to the Countries databaseWe’ll leave the form to your imagining. Let’s build the rest.
In Notion, an integration connects a workspace with third-party apps, like Zapier. Each integration includes a token that allows other apps to exchange information with Notion and make updates to the workspace.
Within a Notion page:
Title
property Full Name.Title
property Country. Give it any three countries.Relate
the databases via reciprocal Country and Submissions properties.To the page containing your Submissions and Countries databases, add your integration:
•••
menu at the top-right, choose + Add connections
at the bottom, then choose your integration.Create Database Item
.Title
) property with the webhook’s full_name value. (Country remains blank.)Find Database Item
.This is where the magic happens.
updatedPage
— ID
from Step 2 (the created page in Submissions).propertyName
— The name of the Relation
property to populate. In this case, Country.relatedPage
— ID
from Step 3 (the found page in Countries).token
— The Internal Integration Token from your custom integration (which you left open to copy). Click Show
then Copy
.Code
area. No updates required, as all variables are provided are provided from Input Data
.
let requestURL = 'https://api.notion.com/v1/pages/' + inputData.updatedPage;
let bodyJSON = JSON.stringify({
"properties": {
[inputData.propertyName]: {
"relation": [
{
"id": inputData.relatedPage
}
]
}
}
});
fetch(requestURL, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${inputData.token}`,
'Content-Type': 'application/json',
'Notion-Version': '2022-06-28'
},
body: bodyJSON
})
.then( response => response.json() )
.then( response => {
callback(null, response)
});
For anyone who may be curious:
PATCH
request to Notion’s API.Authorization
header.Relate
.To Relate
multiple pages, you can add additional objects within the relation
key’s array.
Once you’ve successfully configured the demo, bolster your Notion automations with Relation
property updates. If you hit any snags along the way, shoot me your questions on Twitter, LinkedIn or YouTube.