Skip to main content

Hey automators! I’ve got something special for you today :)

This content was originally created by William Nutt, the Notion expert behind Notion VIP and Notion A-to-Z. See the original post, Automate Notion Relations with Zapier, and companion video.

With his permission, here’s his blog post. Be sure to check out his blog as well.


Zapier is essential to architecting a cohesive and streamlined system with Notion. It powers automations and 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.

The Scenario

As a framework for our configuration, imagine…

  • A contact form has two fields: Full Name and Country.
  • When submitted, the form sends a webhook to Zapier, with the values of Full Name and Country contained in query strings.
  • Zapier adds the submission to the Submissions database in Notion. It contains two properties:
    1. Full Name — the Title property
    2. Country — a Relation to the Countries database

We’ll leave the form to your imagining. Let’s build the rest.

Generate a token.

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.

  1. Visit notion.so/my-integrations.
  2. Create a new integration with a name like “nWorkspace] :: Zapier Extension.” Ensure your intended workspace is selected, then Submit.
  3. Leave the tab open for copying the Internal Integration Token later.

Create the databases.

Within a Notion page:

  • Create a Submissions database. Rename the Title property Full Name.
  • Create a Countries database. Rename the Title property Country. Give it any three countries.
  • Relate the databases via reciprocal Country and Submissions properties.

Add your integration.

To the page containing your Submissions and Countries databases, add your integration:

  • From the ••• menu at the top-right, choose + Add connections at the bottom, then choose your integration.

Create the Zap.

Step 1 (Trigger) — Receive the webhook.

  • Create a Zap triggered by a webhook that receives two values: full_name and country.
  • Provide a test submission where country matches an item in your Countries database.

Step 2 — Create item in Submissions.

  • Using Zapier’s standard integration (not your custom “Zapier Extension”), the first action after the trigger is Create Database Item.
  • It creates the item in the Submissions database and populates the Full Name (Title) property with the webhook’s full_name value. (Country remains blank.)

Step 3 — Find the country.

  • The next action uses the standard Notion integration to Find Database Item.
  • It searches the Countries database for the webhook’s country value.

Step 4 — Relate the country. ✨

This is where the magic happens.

  • Choose Code by Zapier as the app and Run JavaScript as the event.
  • Add three input values:
    1. updatedPage — ID from Step 2 (the created page in Submissions).
    2. propertyName — The name of the Relation property to populate. In this case, Country.
    3. relatedPage — ID from Step 3 (the found page in Countries).
    4. token — The Internal Integration Token from your custom integration (which you left open to copy). Click Show then Copy.
  • Paste the following code into the 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": { rinputData.propertyName]: { "relation": p { "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:

  • This JavaScript make a PATCH request to Notion’s API.
  • The page to update is included in the request URL.
  • Your token is included in the Authorization header.
  • The request body includes the property to update and page to 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 William your questions on TwitterLinkedIn or YouTube.

About William Nutt

In addition to managing the two most popular independent resources, Notion VIP and the Bulletproof methodology, William works directly with Notion on a variety of special projects, including the Help & Support page, the Certified Consultants program, and a training curriculum for their global support team.

↗️ Read the original post

Hey there @nicksimard ,

Thank you so much for sharing this incredibly valuable information! I truly appreciate it.

I've actually given this solution a try, and while it might work for certain specific cases, I've found that it doesn't fully address the persistent limitation of Zapier's inability to update Relation properties. This has been a major source of frustration for me. I absolutely love Zapier and it has greatly benefited my workflows, but this limitation keeps popping up as a recurring obstacle.

I'm really eager to hear from other users to learn how they have been working around this limitation. If anyone has found creative solutions or alternative approaches to handle Relation properties, please share your experiences. Let's come together and brainstorm ideas to overcome this challenge!

Once again, thank you for sharing this information and I'm looking forward to hearing from fellow Zapiers who have encountered this limitation and found ways to navigate around it.

Cheers!

Aurora :)


Hi,

 

I’m getting an error when I run this code:
 

Failed to run your JavaScript code

SyntaxError: Unexpected identifier

 

If i put in an online code bin tool such as JS Bin, I am told the $ next to Bearer is the unexpected token. 

I do not know how to resolve this issue. Please help


Hey @Flow Movement 

I was experiencing the same problem but managed to fix it using the code from the original blog post instead of the one of the post here in Zapier. It’s as follow:

let requestURL = 'https://api.notion.com/v1/pages/' + inputData.updatedPage; let bodyJSON = JSON.stringify({ "properties": { :inputData.propertyName]: { "relation": n { "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) })

Hope this helps! 👋


Hi there, this seems like a great workaround! Excuse my ignorance but how do I send the Notion db properties to the zapier webhook and then what do I do with the Notion integration token? Thank you!


Hi there, this seems like a great workaround! Excuse my ignorance but how do I send the Notion db properties to the zapier webhook and then what do I do with the Notion integration token? Thank you!

 

Hi @Adriang,

Both the Notion db Properties and the Token you add in the Code Zap as “Input Data”

Hope this helps! 👋


Thanks so much!


Am confused. For Step 1, where do you put the Zapier Webhook URL in Notion, so that you receive the new Notion content? And how does that webhook URL relate to the Integration Secret created in the step before?  


Hi @ahaedius, great question! 🙂

Ah, the example contact form was set up to send the submission data to the Zap’s webhook URL but that’s not shown in the video or outlined in the tutorial. Using a webhook for the trigger it isn’t required for the Code by Zapier action that relates the two database items together to work. So you could use whatever trigger makes most sense for your workflow. 

The Integration Secret value from Notion would be used as input for the Code action:

21c43b23626b440d5577816618dc93fd.png
 

The Code action is what would relate the Notion item that was created by the Create Database Item action, to the country that was found by the Find Database Item action.

Hope that helps to clarify things. Do let us know if you have any further questions or run into any issues in setting it up! 


Reply