Sep 27, 2019 01:41 PM
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:
I set up a Zap that:
The webhook component is a Catch Hook and I append the webhook URL with the record ID of the Airtable record:
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:
A few comments:
Webhook -> AT Find Record -> Do Something -> AT Update Record
which would be a no-code option.
Anyway, hope you might find a use for this. Any comments or questions - let me know.
JB
Nov 06, 2019 05:56 PM
:trophy:
This is an absolutely brilliant solution for the hard to reach handoff - I love it!
Dec 19, 2019 09:30 AM
Thank you for this. Can the Zap also be triggered without clicking the webhook URL manually?
Dec 19, 2019 10:36 AM
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