Separating Data from the Text of an WebHook

Sending Multiple Data Frields Via a Webhook?

I’m trying to send data from Airtable to Make via a Webhook so that I can create a WooCommerce product on my website.

I have used an Airtable automation to send an email to Webhooks and included multiple data fields in the body (text) of the email (product descriptions, number of products in stock, product image url, etc.). My problem is that that I can’t separate our the individual bits of data to map against my WooCommerce integration.

One way to get around this would be to create a separate Scenario for each data field I want to update, but that seems like a lot of work.



Hey Dustin,

I would change the setup to send the data to a custom webhook, instead of mailhook.

  1. Create webhook
  2. Change the Send an email in Airtable to “Run a script”.
  3. In the script copy this:

—Start of script—

let config = input.config();
let body = {
recordID: config.recordID,
name: config.name,
email: config.email,
mobile: config.mobile,
land_line: config.land_line,
first_name: config.first_name,
last_name: config.last_name,
status: config.status,
stage: config.stage
}
let data = {
method: “POST”,
headers: {“Content-Type”: “application/json”},
body: JSON.stringify(body)
}
let call = await fetch(config.webhook, data);
console.log(call)

— End of script —

Replace the variables or data structure in the body, like name and mobile with whatever you need to send (Slug, Type, Status, etc…)

Then edit your input variables in the script:

This will send a structured JSON object to your scenario.
Hope this helps, and if the script is too much you can play with editing your email message to send some structured object.

4 Likes

Thanks for this, I think you’ve got me o the right track. I have a follow up question:

  • How is the script sent to Make? The Webhook is waiting for an email and I don’t see a place in the script to include an email.

So in this situation, you would replace your “Mailhook” with a webhook:
Screenshot 2023-11-27 at 8.39.22 AM


2 Likes

I appreciate it,

That gets me a step closer, but I worry that I’m way out of my depth. I’m not sure how to edit the JSON code (hot to google JSON), and then do I add an action to send an email to the Webhooks? How do I get it to include the script?

Above you mentioned “and if the script is too much you can play with editing your email message to send some structured object.” How might I do that?

Hey Dustin,

To edit the code basically all you are doing is formatting a collection of key-value pairs.

Looking at my script for example,

we are defining a recordID field to send in the data, and we assign this to the value config.recordID, which is the variable we set up in airtable.

If you copy the script and delete the inside of the body, you would have just
let body = {}

Then define all the variables you want to send in the data (these will be accessible by
config.[variableName]

So in your case, you would add an input variable in Airtable (bottom of this screenshot):

Then select the field (similar to how you select the fields in your email message)

Then for each variable you set up like this, just add it to your body following the same format I used above.

2 Likes

@Dustin_Bajer , @IOA_Harman has definitely set you on the right course here… but rather than sending all of your variables to the webhook, we recommend you send only the Airtable record ID; then insert a module immediately after the webhook to get a row in Airtable.

This way, you will not need to constantly update the key value pairs every time you add a field to the payload - you will always have a snapshot of all new fields each time the second module fires.

Next level would be to send one other parameter to the webhook which we call ‘method’. This gives you flexibility to add routes to your scenario (e.g. Route 1 = Create, Route 2 = Update)

So in summary:

  1. Use the handy script to call the Make Webhook
  2. You only need to send a single parameter to the webhook, which would be the record ID (expose it by creating a Formula column, into which you write record_id()
  3. But, make it more flexible by sending a method parameter (e.g. create)
  4. In your Make scenario, immediately after the webhook module, insert an Airtable > Get Record module …
  5. Wire up the rest of your scenario, with added option of routes after the Get Record module, to execute whichever method you need to make happen.

This makes it a bit easier to maintain in the long run
:rocket:

3 Likes