Help

Add "any" functionality to Airtable using Zapier Webhooks

4452 3
cancel
Showing results for 
Search instead for 
Did you mean: 

I was thinking about how to add some functionality to a base and, for the base user, how they would trigger this. In most web apps functionality will be invoked by the click of a button - save edits, delete a record and so on - but this button functionality isn’t available in Airtable. But…Zapier provides a webhook component that can be invoked to kick off a Zap.

I frequently use Zaps in my bases and they are mostly triggered by the standard Airtable triggers - new record or new record in a view. One downside to this, which this demo gets around, is that a record can only be triggered once (or once as a new record and once in a given view). By using webhooks to trigger the functionality, it can be executed an arbitrary number of times for any record.

My demo for this is based on translating content from one language to another. I have some text in English and I want to translate each record of content into German:

Screenshot 2019-09-27 at 21.06.36.png

I set up a Zap that:

  • triggers on-demand
  • gets the EN content
  • translates the EN content
  • writes the translated content into another field in the same record:

Screenshot 2019-09-27 at 21.09.06.png

The webhook component is a Catch Hook and I append the webhook URL with the record ID of the Airtable record:

Screenshot 2019-09-27 at 21.11.18.png

The record ID gets passed from the webhook component to the 2nd component in my Zap - a run python component with this code:

import json
import requests

output = {}

id = input_data['id']
get_url = 'https://api.airtable.com/v0/YOUR_APP_ID/Translation%20Webhook/' + id


get_headers = {
    'Authorization': 'Bearer YOUR_API_KEY'
    }

response = requests.get(get_url, headers=get_headers)
data = response.json()
en_text = data['fields']['EN']

output['en_text'] = en_text

The output of this component is the EN text and this gets passed to a Zapier translate component, which translates it to German, passing the translated text to the last component - another Run Python. This component takes the translated text and sends it back to the same record in Airtable using:

import json
import requests

de_text = input_data['de_text']
id = input_data['record_id']

return_url = 'https://api.airtable.com/v0/YOUR_APP_ID/Translation%20Webhook/' + id

headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_API_KEY'
    }

return_data = {
  "fields": {
    "DE": de_text
  }
}

response = requests.patch(return_url, headers=headers, json=return_data)

Once all set up, you can click on the webhook URL in any record and trigger the translation Zap:

Screenshot 2019-09-27 at 21.18.44.png

Screenshot 2019-09-27 at 21.17.26.png

A few comments:

  • the functionality here is a translation, but, of course, it could be anything (yes, I know AT has a translation block already :winking_face: )
  • I’ve shown this with an update action per record, but you could easily have the same webhook URL in every record (i.e. no record ID params) and the webhook triggers an update to multiple records in a view - in this example, maybe all of the records without a German translation.
  • Clicking on the webhook URL opens a new browser tab and you get a JSON response to the call. A bit tedious, but not terrible.
  • This Zap uses 4 components, which needs a paid Zapier plan. I’ve used webhook triggers with fewer components, so it is doable on a free Zapier plan.
  • I’ve used run python components, which, obviously, you need some familiarity with code to be able to implement. However, very possible that you could do:

Webhook -> AT Find Record -> Do Something -> AT Update Record

which would be a no-code option.

  • For the coders amongst you, lots of opportunities to implement more complex functions than AT natively provides. One of the things that AT doesn’t do right now, for example, is allow you to iterate on items in an array field - example, sort and dedupe an array of values. Very easy to do this in a code component triggered by a webhook call. (Something I might have a go at when I get some time).

Anyway, hope you might find a use for this. Any comments or questions - let me know.

JB

3 Replies 3
Grant_Andrew
5 - Automation Enthusiast
5 - Automation Enthusiast

:trophy:

This is an absolutely brilliant solution for the hard to reach handoff - I love it!

Tiberius
6 - Interface Innovator
6 - Interface Innovator

Thank you for this. Can the Zap also be triggered without clicking the webhook URL manually?

Yes, you could trigger the Python component with a timer/scheduler module or in response to some other event, e.g. new record in Airtable