Automating the publication of my Out of Ten reviews using Zapier and Notion

Saturday, March 2, 2024

Zapier is a Software as a Service (SaaS) company that has been around since 2011. Its core product is automation workflows i.e. when this happens do that. As readers of my previous post will know I store all of my out of ten reviews in a Notion database. Until now I have triggered my Github workflow manually after adding a new review to Notion. My Github Actions workfow then calls Notion’s API to retrieve the database entries, render them using the Hugo static site generator and upload to my web site. Given my curiosity around Zapier’s free tier I was keen to see if I could automate the invocation of my Github Action workflow using Zapier’s “no code” automation. Spoiler: I couldn’t manage it with no code and I needed to bring some Python code to my Zap to get the job done.

Zapier AI assistant

As hinted above my requirement is simple: when I add a new review to a Notion database trigger a Github Actions workflow to publish it. Of course a hobbyist like me is not Zapier’s target market and, of course, there are many other ways I could automate this. And it’s true that I am hesitant about using SaaS companies like Zapier because:

  • nothing is guaranteed with them e.g. financial difficulty, takeover, change of strategy, deprecation of a service or financial realities forcing the pricing to change significantly

  • even if I were a paying customer (which I am not - this experiment is going to use Zapier’s “always free plan”) it seems that signing up for a dozen or more SaaS offerings is the way many people think things are done. Surely this can quickly become complicated, with too many moving parts and too many bills

  • with great power to everyone can come a great mess. The initial velocity that tools like Zapier provide may lead to a lot of tangled automations in the future; automation that could prove difficult to unwind and maintain

That said there are a lot of businesses who will benefit significantly from automating some of their workflows e.g. when an e-mail arrives do this or when something happens on social media add a record to a Google sheet. And securely integrating APIs from various services isn’t simple. So I can see how Zapier could save some types of business significant effort.

Attempt One: AI for everything

The sign-up process for Zapier is slick and there is even an AI widget to create the ‘Zaps’ for you. I gave this a try with the prompt:

“When I add an item to a Notion database run a GitHub action’s workflow”

The AI understood my request but I was disappointed to see the message “GitHub Actions” may not be currently supported. Send us a request to get it added to the App Directory" pop-up. This wasn’t going to be as easy as I hoped.

Nonetheless adding the Trigger event to a Zap was extremely simple. I selected the Trigger for Notion as “New Database Item” and followed the wizard on screen i.e. log-in to Notion via OAuth2, give it some permissions, choose the Notion database I want to monitor for events and test the trigger.

Creating a new database item trigger in Notion

Worth noting that Zapier is event driven, but it mostly needs to poll to find those events. On the free plan the polling frequency is every 15 minutes. So when I create a “New database item” trigger it means behind the scenes some code runs on Zapier’s servers every 15 minutes, which calls Notion to see if the state of my database has changed. That’s 96 HTTP requests a day or about 35,000 a year. This means if Zapier have 500,000 users each with one Zap that is polling for events against a Notion database, Zapier are making over 17 billion requests a year to Notion’s API. I am not sure if Notion offer Zapier a batch based API to poll (but I doubt it given the permissioning). So Zapier with all of its connectors must be generating an incredible amount of HTTP traffic to various APIs.

Attempt Two: Webhooks by Zapier

Zapier on the free plan offers only two-stage Zaps; meaning you can only create workflows that have a trigger (“when this happens”) and a single action (“do that”). On paid plans you can create more complex chained workflows. Also not all actions are available on the free plan.

The Zapier AI suggested an alternative: to perform a HTTP POST using a ‘webhooks by Zapier’ step, which I didn’t investigate further because I would have to to pay 20 USD a month; reasonable value I suppose if you are doing something other than automating a small part of your personal website. But for a cheapskate like myself the webhook route was discounted.

Attempt Three: Cheat by updating a Github comment

Zapier has some built in Github actions e.g. Create Comment or Update a Pull Request. So I thought if I create a dummy issue in Github and update it using my action I could still escape with a no code solution. After a few minutes I had adjusted my Github Actions workflow to trigger when an issue is edited:

1on:
2  push:
3    branches: ["main"]
4    
5  issues:
6    types: [edited]
7
8  workflow_dispatch:

Next I went to Github and manually created the issue below. I configured the Zapier action to add a new comment:

Adding a comment to my Github issue

As you can see in the screenshot above Zapier added the “Stolen Focus” comment (mapped from the title of my database item retrieved by the trigger action). So this approach did work, but it had one issue. Notion does not have a save button when editing a database entry. So when I key a title for my out of ten review and move to the next field, the database entry is already created and with each field I add it is updated. Depending on when the 15 minute polling happens this might not be an issue, but during my testing it was - the event fired prematurely; my Github workflow failed as mandatory fields were missing; the ‘New database event’ would never be seen again. I experimented by changing the Notion trigger event to be ‘Updated Database Item’, but again the events fired prematurely after each field was updated and before I had keyed all of the fields.

The Zapier solution to this is to add a Filter step between the trigger and the action. As shown below this means you can choose not to continue to the action if mandatory fields are not present. Unfortunately filters count as another step and the free plan only allows two-step zaps… so (again!) without paying 20 USD a month this was not a viable option.

Attempt Four: A Code Solution

Zapier’s free plan does surprisingly allow you Code by Zapier actions. They have a 128MB memory limit and a 1 second run-time - more than enough to validate a few fields and call the Github REST API to trigger a workflow. The Python code for my action is below:

 1import requests
 2import json
 3
 4if 'RATING' not in input_data:
 5    output = {'status': 'Skipping as no Rating found in record'}
 6    return []
 7
 8github_token = '<REDACTED>'
 9
10repository = 'planetjones/my-repo-name'
11workflow_name = 'my-workflow.yml'
12
13github_api_url = f'https://api.github.com/repos/{repository}/actions/workflows/{workflow_name}/dispatches'
14
15payload = {
16    'ref': 'main',
17    'inputs': {
18    }
19}
20
21headers = {
22    'Authorization': f'Bearer {github_token}',
23    'Accept': 'application/vnd.github+json'
24}
25
26response = requests.post(github_api_url, data=json.dumps(payload), headers=headers)
27
28if response.status_code == 204:
29    output = {'status': 'Workflow triggered successfully'}
30else:
31    output = {'status': f'Error triggering workflow: {response.text}'}

I set the RATING variable from the Rating field of the Notion database entry triggering the action:

Passing property to Zapier code action

The premise of my implementation is that is that I must update the Rating field last; meaning only when that Database updated event fires will I have a complete review. With the complete review Zapier can trigger my Github Actions Workflow to retrieve and publish it on planetjones.net. This solution proved effective: partially completed database items were skipped by the if statement and only completed database entries resulted in the Github Actions workflow being triggered.

What brought some joy was Github’s beta for fine grained Personal Access Tokens (PATs) - but even when generating the token with just the Actions permission it can do a lot more than trigger Github Actions workflows. What did not bring joy was Zapier does not have a secure way of storing secrets for use in code actions. The only solution I am aware of is to unwind security best practice and paste the token value into the action. Potentially with Zapier’s Platform API or Custom Actions this would be possible. I don’t know.

Conclusion

It was fourth time lucky for me. I don’t like the PAT token in the code and I won’t stick with this solution for long. However it is effective and it’s free, so I cannot complain.

This was a useful exercise to explore Zapier and gain an appreciation of the hoops people have to jump through in order to create no code or low code integrations. In fairness if I had been on a paid plan I wouldn’t have needed the Python solution, as I could have used a filter step. And yes of course it’s an over-engineered solution for what I need - simplest would have been to take advantage of Github’s 2000 free CI/CD minutes per month and run my Github action workflow using a schedule trigger i.e. do the polling myself. But I learnt something about Zapier and my out of ten reviews will update quicker in the future - so something useful came out of this experiment.