Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Aug 11, 2020 02:04 AM
Hi all,
I need a bit of help with a simple script to trigger a webhook URL. I don’t need to collect or post any info from the webhook, just to trigger it, like clicking a link.
Any ideas on what that script might look like?
Cheers
Matt
Aug 12, 2020 10:46 AM
Hi!
I’m also interested to this!
Aug 12, 2020 12:25 PM
Welcome to the community, @Matt1! And welcome back, @Jonathan_Blair-Joly! :grinning_face_with_big_eyes:
The bare-bones pieces you need are the webhook URL and the fetch
call to it. Here’s an example with an Integromat webhook call:
let url = "https://hook.integromat.com/xxxxxxxxxxxxxxxxxxxxxxx";
await fetch(url);
If you want to pass anything to it, append it to the URL. For example, I use a webhook to call an Integromat scenario to generate a PDF version of the invoice for a specific record, and save it back into the record’s attachment field. When I click the button in a button field on the invoice record, it calls this script, and passes the ID of the record in the webhook like this:
let url = "https://hook.integromat.com/xxxxxxxxxxxxxxxxxxxxxxx?recordID=";
let table = base.getTable("Invoices");
let view = table.getView("Outstanding: Actions");
let record = await input.recordAsync("Pick a record", view);
await fetch(url + record.id);
Aug 12, 2020 02:36 PM
Awesome!
Thank you @Justin_Barrett, I’ll integrate this with the new automation feature.
Thanks again!
Aug 12, 2020 02:50 PM
First example worked perfectly.
For the second one with the record id append to the url, I got that error :
TypeError: input.recordAsync is not a function
at main on line 5
Do I need to replace “Pick a record” with something? What about taking any record within a specific view or all records within a specific view?
Aug 12, 2020 04:05 PM
The input.recordAsync
method only works when you click a button in a button field to trigger a script in the scripting block. Your earlier note didn’t mention going the automation route. For that, you’ll need to add an input variable to your script action step, passing in the record ID of the triggering record from the trigger step. Let’s say you named that input variable recordID
. That would then be available via input.config()
. Here’s my earlier example tweaked to work for an automation:
let url = "https://hook.integromat.com/xxxxxxxxxxxxxxxxxxxxxxx?recordID=";
let config = input.config();
await fetch(url + config.recordID);
Aug 12, 2020 04:08 PM
Sorry, I forgot to answer your follow-up question:
The automation system works using a triggering record, either a new one added to a table, or a record entering a specific view via a filter. If you want the automation’s script to run on a collection of records, that’s doable, but you’ll need to modify your script to search for the records you want, and also come up with a trigger mechanism that makes sense for your use case. You haven’t shared details about your base design, so I can’t offer any specific suggestions on that front.
Aug 12, 2020 11:25 PM
This is great. thanks so much!!
Aug 13, 2020 04:41 AM
Sep 14, 2020 12:57 AM
@Justin_Barrett How would I pass multiple input variables in the URL and via config…?