Skip to main content

Hi,

I have recently started using Zapier to transfer new orders from my website to an obscure book-keeping software called Kashflow. It has a Zapier integration, although there are some things it does not cover.

Each customer on Kashflow requires a unique customer code. By default, Kashflow autogenerates the code from the first four letters of the first name followed by a number that autoincrements if there are existing customers with that code (e.g. "John Smith" -> "JOHN56" if there are 55 Johns already on Kashflow).

I wanted a code template that was less simple, so when manually entering customers on Kashflow I used the first four letters of the surname, the first letter of the first name, and a number (e.g. "John Smith" -> "SMITJ9"). There is a button with JScript on Kashflow that increments the number on a duplicate.

The Zapier Kashflow integration lets you set the customer code. It was easy to use Formatter to truncate the surname and first name for the code. I tried putting the number "1" at the end of the field, hoping that Kashflow would automatically increment it in the case of a duplicate code. However, Zapier would stop the process as soon as a duplicate customer code was found, and the customer was not created on Kashflow.

I found it is possible to use Paths to work around to a limited extent. I can use the Kashflow search integration to check if there is a customer with the same code before creating the customer and invoice. If there is a customer with the same code, then Storage by Zapier increments the code number by 1, and then there is another Kashflow search to see if the customer code is in use (see attachment for a simplified basic visual representation of what it looks like).

The problem with this is that without some way to conditionally loop this series of steps, I would need to duplicate all of the subsequent steps ad infinitum to make sure I prevent Zapier encountering a duplicate code. Also, if I wanted to make a single change to any of the downstream steps I would need to copy it over to all the duplicate steps.

Any suggestions on more elegant ways to address this problem would be much appreciated.

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:

81209ba9c78ab0c2daf4c3d0fd1f5707.png

And that created separate line item fields like so:

2e7f24d983f9229d11a57b152985cf42.png

Which made the different line items fields available to select individually in subsequent steps:

da11883b604631ceec7ccd9280672c7b.png
 

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.


Attachment


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! 🙌✨