Help

Re: Using Scripting Block to push a webhook on button click

4379 1
cancel
Showing results for 
Search instead for 
Did you mean: 
dave_brand
6 - Interface Innovator
6 - Interface Innovator

Hey, is it possible to create some Action Buttons to push webhooks with json data with the scripting block?

39 Replies 39

Oooh, thank you!! That’s a really great idea! :slightly_smiling_face: I haven’t jumped on the ball yet of creating my “Airtable Hot Tips” video series yet (which was originally YOUR idea for me!), but this would be a great one to kickstart the series! :slightly_smiling_face:

Especially if it included a little script snippet to demonstrate how to call an Integromat webhook from a button or an action.

Hi Bill,

thanks for your response.
It seems to be a cache issue. After i cleared the cache of my browser the button works as expected. So the problem is solved.

Have a great start in the week.

Kai

Hi Scott,

As Bill said it’s possible, and you can pass the record ID like you would for the Button/Webhook trigger :

let url = "https://hook.integromat.com/xxxxxxxxxxxxxxxxxxxxxxx?recordID=";
let inputConfig = input.config();
await fetch(url + inputConfig["recordID"]);

This allows to trigger Integromat scenarios immediately when specific conditions are met in Airtable, without having to set a periodic schedule in Integromat (thus reducing the operations count & latency).

Screen Shot 2021-01-20 at 4.38.09 AM

Thanks for the JavaScript code!

This is awesome. It seems like every time I’m trying to solve a problem, the solution has just recently been posted in the forum. Thanks for sharing the code and knowledge.

Yep - this is a great example.

Caution

You may also want to test to see if the webhook fired and if not, determine the cause of the failure if the process is a mission-critical process.

My current use case isn’t mission critical, but I’m interested in using this for automating other processes in the future in the future.

@Bill.French do you know of a simple way to test to see whether the webhook has fired or not? Would you suggest adding something to the javascript?

I can think of several ways to do this that require way more steps (like adding a step to the initial automation that checks a box, then adding an uncheck box step to the webhook function), but wonder if there’s an easier way in the script itself to check to make sure that the webhook has fired properly.

Thanks!

It’s not really a question of firing; it’s determining what happened after the fire. If it failed or succeeded typically depends on what the response is from the hook. They vary in what (if anything) is returned when the request is made, but in most cases they conform to API standards issuing an HTTP response code.

I just thought I might add what I have done to this as I stole a few things and mashed them together…

I have an automation, when a particular sales status is reached, I want to send a JSON payload with two parameters. Now I know I could send one parameter, but this webhook is actually set off not just by Airtable and there are times that the extra parameters are not in Airtable, e.g. they are sent from the automation.

let url = "<webhookURL obv deleted here>";
let inputConfig = input.config();
let payload = {
"record": inputConfig["recordID"],
"emailType": inputConfig["salesStatus"],
}

let postOptions = {
method: "post",
headers: {
'Accept' : 'application/json',
},

body: JSON.stringify(payload)
}

await fetch(url, postOptions);

So I am passing it, in this instance, the recordID and the salesStatus from my record. You could really continue building out the JSON payload with as much information as you want, although of course you could also grab this by sending just the ID and then grabbing the rest in Integromat…
image

So people above seem to be getting back results, unsure what they are doing with that exactly though??
e.g. what is this doing?

const postResults = await fetch(url, postOptions);
const jsonPost = postResults.json();
let id = (jsonPost.field + " = " + jsonPost.value);