Help

Parsing Data from Webhook

Topic Labels: Automations
Solved
Jump to Solution
2452 8
cancel
Showing results for 
Search instead for 
Did you mean: 
Good_Ink
5 - Automation Enthusiast
5 - Automation Enthusiast

We use a webhook from Shopify to capture order data in Airtable. When the webhook comes in, we create a record in Airtable with pertinent order data. I want to parse out the line items in the order into another table for use in creating a packing slip.

Here is sample data: Airtable - MA Test
The Data table represents the data as it comes in from the webhook.
The Desired Output table represents the ideal output. This is where I need help, creating an automation/script to parse out that data into new rows.

Thanks for your help!

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

I’ve put something together here that should do what you’re looking for

It currently only handles 4 line items, but you can make it handle as many as you want by just modifying the formula

Screen Recording 2022-11-24 at 10.55.30 AM

Works by using formula fields to put the line item name and quantity together, then using an automation to paste that into a linked field to the Desired Output table

The Desired Output table in turn has formula fields to separate the line item name and quantity out

To view the formulas, you can duplicate the base by clicking the title of the base at the top of the screen, then the three horizontal dots on the right, and then the “Duplicate Base” button.

Lemme know if you have any problems setting it up yourself (Or you can also hire me to set it up for you too!)

See Solution in Thread

8 Replies 8

Welcome to the community, @Good_Ink!

I don’t know JavaScript, so somebody else would need to chime in below to help you with writing a script for this.

Since I don’t know scripting, my personal methodology for this would be to use Make.com, which is a no-code/low-code automation platform.

You can either use a Make webhook or their native Shopify modules to receive your Shopify data, and you can loop through your Shopify line items to create the desired output in Airtable that you’re looking for.

This would take a few hours to setup in Make, so I wouldn’t be able to guide you through the entire process here. You can likely figure it out on your own. But if your company has a budget for your project and you’d like to hire an expert Airtable & Make consultant to help you with this, please feel free to contact me through my website: Airtable consulting — ScottWorld

TheTimeSavingCo
18 - Pluto
18 - Pluto

I’ve put something together here that should do what you’re looking for

It currently only handles 4 line items, but you can make it handle as many as you want by just modifying the formula

Screen Recording 2022-11-24 at 10.55.30 AM

Works by using formula fields to put the line item name and quantity together, then using an automation to paste that into a linked field to the Desired Output table

The Desired Output table in turn has formula fields to separate the line item name and quantity out

To view the formulas, you can duplicate the base by clicking the title of the base at the top of the screen, then the three horizontal dots on the right, and then the “Duplicate Base” button.

Lemme know if you have any problems setting it up yourself (Or you can also hire me to set it up for you too!)

Thank you for spending time working on this! I apologize that it took me so long to get back to you. This is nearly perfect for our needs. As every order can vary in size, I'm trying to figure out a way to make the formula dynamic. Any ideas in that regard is appreciated but your efforts thus far are much appreciated.

No worries.  It's built to handle up to 4 line items but should be able to handle dozens, the only limiting factor is the formula fields character limit

I've updated the base to handle 10 line items now and you should be able to recognize the pattern for which value you need to change, you'll just need to extend it to whatever upper bound you're comfortable with

I did expand the formula to accept more line items as well but then noticed a large order of over 100 line items. I am writing a script that will hopefully handle this situation at scale. I will post what I come up with. Thanks again for your help.

Good_Ink
5 - Automation Enthusiast
5 - Automation Enthusiast

I finally got around to writing the code to handle this situation, hopefully it can help someone else.

Assumes you are using the "Run Script" automation action and that you have tables "Data" and "Test." Also change the input variables for your use.

let config = input.config();
let table = base.getTable("Data");
let nextTable = base.getTable("Test");
let items = config.items;
let orderNumber = config.orderNumber;
let id = config.recordID;
let inputItems = items;
let inputQty = config.quantity;
// Define the regular expression pattern for capturing items in the list
let regex = /[^,\s][^\,]*[^,\s]*/g;

  // Use the match() function to find all occurrences of the pattern in the input string
let capturedItems = inputItems.match(regex);
let capturedQty = inputQty.match(regex);

console.log(capturedItems);

for (let i = 0; i<capturedItems.length; i++) {
    await nextTable.createRecordsAsync([
        {
        fields: {
            "Order #": orderNumber,
            "Item": capturedItems[i],
            "Quantity": capturedQty[i],
            },
        },
    ])
}

 

@Good_Ink I was using your code above to do something similar to what you describe, but it threw an error. Any ideas on how to fix it?

Screenshot 2024-04-04 at 1.05.42 PM.png

Hmmm, not sure. I'm assuming you have an input variable setup for items?