Notion VIP Logo
BulletproofA-to-ZConsultingProductivity Nexus
0
Subscribe

Automate Notion Relations with Zapier

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.

The Scenario

As a framework for our configuration, imagine…

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 “[Workspace] :: Zapier Extension.” Ensure your intended workspace is selected, then Submit.
  3. Leave the tab open for copying the Internal Integration Token later.
https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a70b924ec0ea337e6a4_notion-relations-zapier_create-integration.gif

Create the databases.

Within a Notion page:

https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a6fb924ec637b37e4dc_zapier-notion-relation_demo-databases.png

Add your integration.

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

https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a6fb924ec430d37e4f7_zapier-notion-relation_invite-integration.png

Create the Zap.

Step 1 (Trigger) — Receive the webhook.

https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a6fb924ec3e3137e4dd_zapier-notion-relation_webhook.png

Step 2 — Create item in Submissions.

https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a6fb924ecfa8637e4de_zapier-notion-relation_add-database-item.png

Step 3 — Find the country.

Step 4 — Relate the country. ✨

This is where the magic happens.

https://cdn.prod.website-files.com/63e19fb61b378b1f7340fc96/643f2a6fb924ec691e37e4b0_zapier-notion-relation_code-input-data.png
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:

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.

All-in on
the all-in-one
productivity app.
Subscribe →