Hi @All Things Apples
Here’s a guide about how to create a self looping Zap using Webhooks.
NOTE: This is different from the Looping by Zapier app.
Thanks Troy. I’ll look into this as a solution.
Hi @All Things Apples
How did you get on with that guide Troy shared, did that approach work for you?
Want to double-check that things are all squared away here, so please let us know whether you’re in need of any further help at all!
Hi @SamB
Sorry for leaving this topic hanging, I had to change tack at work for a while. I have used Troy’s advice to split the order operation into two Zaps: one to send the WooCommerce data via webhook, and the other to receive, loop until a vacant customer code is found, and then make the Kashflow invoice. I found that instead of Google Sheets, Storage By Zapier and Paths by Zapier were simpler to construct the conditional loop with.
However, I have found a problem that as soon as the WooCommerce order is sent through a POST webhook, most line item fields are stuck together and cannot be called individually. For example, I cannot call “Line Items Sku”, “Line Items Name”, or “Line Items Quantity”. I can only call “Line Items” which contains the information of all line item fields.
I need these to be each recognised as line item fields or the Zap will not work properly. If you have any suggestions they would be much appreciated.
I’m so sorry for the delay in my reply here @All Things Apples!
However, I have found a problem that as soon as the WooCommerce order is sent through a POST webhook, most line item fields are stuck together and cannot be called individually. For example, I cannot call “Line Items Sku”, “Line Items Name”, or “Line Items Quantity”. I can only call “Line Items” which contains the information of all line item fields.
I need these to be each recognised as line item fields or the Zap will not work properly. If you have any suggestions they would be much appreciated.
Hmm, I suspect you may need a Formatter or Code action step to extract the individual line item fields but would need to see the structure of the line item data to get a better idea of what the best approach would be. Can you share a screenshot showing how these line items appear in the Zap? Make sure to blur or remove all personal information (names, emails, addresses etc.) from any screenshots before sharing here.
Looking forward to hearing from you on this!
@SamB Not to worry, I have been far from punctual myself. Thank you for your persistence.
I have attached a screenshot showing how, after passing through the webhook to the second Zap, the various line item fields (sku, quantity etc) have been nested together into a single ‘Line items’ field.
Thanks for sending over that screenshot @All Things Apples!
I did some testing with a Code step using a similar structure to the JSON pictured in your screenshot and was able to get it to separate everything out into different line item fields. I used the Generate with AI feature on a Code step and gave it the instruction of “Parse the Json and output as line item fields” and it made the following code:
import json
combined_items = input_data.get('combinedItems', 'I]')
# Parse the JSON string to a Python object (list of items)
items = json.loads(combined_items)
# Prepare the output as a flat structure
output = o]
for item in items:
# Create a flat representation of each item
flat_item = {
'id': item.get('id'),
'name': item.get('name'),
'product_id': item.get('product_id'),
'variation_id': item.get('variation_id'),
'quantity': item.get('quantity'),
'tax_class': item.get('tax_class'),
'subtotal': item.get('subtotal'),
'subtotal_tax': item.get('subtotal_tax'),
'total': item.get('total'),
'total_tax': item.get('total_tax'),
'sku': item.get('sku'),
'price': item.get('price'),
'parent_name': item.get('parent_name'),
# Extracting the first meta_data entry if it exists
'meta_data_key': iteme'meta_data']t0]d'key'] if item.get('meta_data') else None,
'meta_data_value': itemu'meta_data']t0]d'value'] if item.get('meta_data') else None,
# Extracting image source if it exists
'image_src': itemr'image']['src'] if item.get('image') else None
}
output.append(flat_item)
# Return the output as a dictionary
output = {'items': output}
I made an input field called combinedItems and to the right of it I selected the field containing the JSON I’d typed up. For your case you’d want to select the Line Items field pictured in your screenshot instead:
And that created separate line item fields like so:
Which made the different line items fields available to select individually in subsequent steps:
Hope that helps. Keep us in the loop on how you get on with this, eager to ensure you’re all squared away here!
Thank you, I used the AI prompt you recommended and am currently testing it with incoming orders.
@SamB Using the JSON parsing worked well, thank you. The fields can now be called individually.
Unfortunately when I tested the zap another issue reared its head. I am under the impression that if you do not define the data fields in a POST webhook, then it will pass on all data from the previous step. That is how I set up the initial triggering zap that sends the data to this looping zap.
I do something similar in the main looping zap to make it repeat. I use a search step to call up the order followed by another POST webhook to repeat the zap from the top. However, I also put in an error handler in case the original order can’t be found (see screenshot). When an order came through the system, the zap worked fine until it looped, at which point it lost all data. Do you think putting an error handler in between the order search step and POST webhook could interfere with the data being picked up?
I could go and add every single field (30+) from the WooCommerce order to the POST webhook, but I am reluctant do do in case the WooCommerce integration makes any changes or adds extra fields.
Glad to hear using a Code step to parse the JSON did the trick @All Things Apples!
Unfortunately when I tested the zap another issue reared its head. I am under the impression that if you do not define the data fields in a POST webhook, then it will pass on all data from the previous step. That is how I set up the initial triggering zap that sends the data to this looping zap.
I do something similar in the main looping zap to make it repeat. I use a search step to call up the order followed by another POST webhook to repeat the zap from the top. However, I also put in an error handler in case the original order can’t be found (see screenshot). When an order came through the system, the zap worked fine until it looped, at which point it lost all data. Do you think putting an error handler in between the order search step and POST webhook could interfere with the data being picked up?
I did some checking on this end but couldn’t see any reports of the presence of an Error Handler causing a webhook’s data to be cleared. I’d recommend reaching out to our Support team to have that investigated further in case it’s a bug. You can get in touch with them here: https://zapier.com/app/get-help
In the meantime, could you have the Zap store the information somewhere so it’s not lost? Perhaps you could use an app like Zapier Tables? Thinking that way the actions in the loop should be able to still reference the stored information instead.
Keen to ensure this gets sorted so keep us updated on how you get on!
Hi @SamB. I removed the error handler between the order search and the POST webhook and the zap now seems to work fine. I might run some tests later and make a bug report to Support.
Thanks for all your assistance, the zap seems to run great now. It’s been a long road, thank you for sticking with me.
That’s fantastic news @All Things Apples! I’m so pleased that it’s working now. Very strange about the webhook data getting cleared though so definitely reach out to our Support team when you get a minute - be good to get that investigated further as it shouldn’t be happening!
Thanks for all your assistance, the zap seems to run great now. It’s been a long road, thank you for sticking with me.
Happy to help! Huge kudos to you for sticking with it and getting it across the finish line!