Help

How do I parse input config of Array/Object from webhook?

Topic Labels: Automations
339 5
cancel
Showing results for 
Search instead for 
Did you mean: 
sorapool
5 - Automation Enthusiast
5 - Automation Enthusiast

I've created an automation 'When webhook is received..' -> 'Run Script'.  Inside that script, how do I add arrays/objects as inputs to the script received from the webhook?

Here is an example payload:

{"AccountId":"820","MessageType":"ContactModified","Parameters":{"Contact.Id":"73953","ProfileChanged":"True","Action":"Created"}}

As you can see, 'Parameters' is an object with different keys, depending on what the 'MessageType' is. I just want to accept 'Parameters' as an object in my code so that I can make different decisions.

From what I can tell, AirTable forces me to statically map the input. What happens when $.Parameters.ProfileChanged does not exist, but I've told AT to use it?

5 Replies 5

There are dozens of Javascript experts in this community, so I'm sure that you will get an answer below very soon.

In the meantime, while you're waiting for one of our Javascript experts to answer your question below, I can tell you how to do this in a completely no-code way that doesn't require any programming code at all, and doesn't require any programming knowledge at all.

Instead of using Airtable's incoming webhooks, you can setup an incoming webhook with Make.

Make will automatically parse the input of the JSON for you, and then you can make different decisions about what you want to do in Airtable by applying conditional filters.

Check out the screenshot below for an example of how easy this would be to setup in Make.

p.s. If your company has a budget for your project and you’d like to hire an expert Airtable consultant to help you with any of this, please feel free to contact me through my website: Airtable consulting — ScottWorld 

Screenshot 2024-03-17 at 3.41.00 PM.png

Dan_Montoya
Community Manager
Community Manager

If you call a script from your webhook you can use something like:

 

if(debug==="1") (console.log("reponseData" , reponseData));
Screenshot 2024-03-17 at 4.52.06 PM.png
 

re: From what I can tell, AirTable forces me to statically map the input. What happens when $.Parameters.ProfileChanged does not exist, but I've told AT to use it?

Assuming you're talking about having set up an input variable for it, then it'll just assume that the value of that input variable is null

Hi,
You can choose input variables at the left side. You can change their name, for example I would change Contact.Id to Contact_Id
Then you can parse them inside the script
Read about ES6 JS Destructuring for more details. Especially Object destructuring, and spread/rest syntax

A short example including default value set, when parameter might exist or not...

Alexey_Gusev_0-1710761309674.png

In your case, you can do

let payload={...input.config()}

 


Inside that script, how do I add arrays/objects as inputs to the script received from the webhook?

...

From what I can tell, AirTable forces me to statically map the input. What happens when $.Parameters.ProfileChanged does not exist, but I've told AT to use it?


As you can see, Airtable webhook automations leave a lot to be desired. You currently cannot receive the an entire array/object as an input variable.

Do you have any control over the shape of your payload? If so, you can JSON.stringify() your entire payload, and then pass that text string to the webhook. Then in your automation script, use an input variable to get the JSON string, and then parse the JSON string to get back the original payload object.