Help

Airtable Webhook Triggered by Airtable Script

Topic Labels: Automations
Solved
Jump to Solution
3326 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Sean_Christense
6 - Interface Innovator
6 - Interface Innovator

Hi,

I’ve been playing around with Airtable and Integromat via Webhooks, and I was wondering if there was a way for two Airtable bases to communicate via webhook and scripts. Here’s the use case:

  • A webhook trigger is set up in Base 1 in an automation.
  • A record is created in Base 2. This triggers an automation to run a script, which posts to the webhook URL from the trigger in Base 1.
  • The automation in Base 1 is triggered by the incoming webhook, and updates a corresponding record.

I’ve used Integromat to trigger webhooks via automation scripts using the following code, but unfortunately it gives me an error when I try the same thing with an AT webhook url:

let data = input.config();

let response = await fetch(`https://hook.integromat.com/********************************
?id=${data.ID}
&email=${data.Email}
`);

console.log(await response.text());

I’d appreciate any help or pointers on updating the script to work. I know that @Justin_Barrett, you’ve posted about this in a few topics, so please forgive if this has already been solved somewhere.

Thanks!
Sean

1 Solution

Accepted Solutions

First off, beginning variable names with capital letters is discouraged in JavaScript. That’s a naming convention typically reserved for class names, which is why those names are colored differently in Airtable’s script editor. It’s recommended to use a lower-case letter to begin variable names.

The main issue, though, is that you’ll need to bring these values in using the input.config() mechanism. My example above was focused on the fetch call itself, which is why I left that part out. Somewhere above the code that I used, you could do something like this (assuming the variable names are changed per my first comment):

const {masterID, mediaID} = input.config()

That will assign both variables to the value of their respective counterparts in input.config().

Then your options variable setup should work with those new variable names:

const options = {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        master: masterID,
        media: mediaID
    })
}

See Solution in Thread

4 Replies 4

Your concept will definitely work with some minor tweaking. Passing in parameters via the URL is a GET request, but Airtable webhooks must be called by passing the data as JSON via a POST request. Here’s the basic setup:

const webhookUrl = "https://hooks.airtable.com/workflows/v1/genericWebhook/......."

const options = {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        propertyName1: propertyValue1,
        propertyName2: propertyValue2
    })
}

let response = await fetch(webhookUrl, options)

Customize the object inside the JSON.stringify() function call based on the data that you want to pass to the receiving automation webhook. You can’t go very deep with your data object (a limitation in the design of Airtable’s webhooks), so I recommend running some tests to see how the data is received before committing to your object structure.

FWIW, if you ever end up doing a similar call from a Scripting block, you’ll have to replace fetch with remoteFetchAsync, but the core process is the same.

Sean_Christense
6 - Interface Innovator
6 - Interface Innovator

Thanks @Justin_Barrett ! This is great, I really appreciate the speedy response.

I’m trying to call specific variables in the stringify section, but I’m not sure how to format it. Should I be using ${data.variablename}? Here’s my attempt so far:

Capture54

Thanks again!

First off, beginning variable names with capital letters is discouraged in JavaScript. That’s a naming convention typically reserved for class names, which is why those names are colored differently in Airtable’s script editor. It’s recommended to use a lower-case letter to begin variable names.

The main issue, though, is that you’ll need to bring these values in using the input.config() mechanism. My example above was focused on the fetch call itself, which is why I left that part out. Somewhere above the code that I used, you could do something like this (assuming the variable names are changed per my first comment):

const {masterID, mediaID} = input.config()

That will assign both variables to the value of their respective counterparts in input.config().

Then your options variable setup should work with those new variable names:

const options = {
    method: "POST",
    headers: {
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        master: masterID,
        media: mediaID
    })
}
Sean_Christense
6 - Interface Innovator
6 - Interface Innovator

@Justin_Barrett Amazing! Thank you so much, I really appreciate it. Hopefully this is useful to other people, to avoid using something like Zapier or Integromat to handle Base to Base calls.

Thanks!