I want to create an InvoiceNinja invoice from a WooCommerce order and my issue is how I can dynamically map all WooCommerce order line items to InvoiceNinja invoice items. Of course I can manually map line item 1 to invoice item 1 and so on. See screenshot.
Thanks for posting here and welcome to the community!
If you have an array in the previous node you can use the Split-Out Node to separate the fields you need into iterable items. Then you can reference them in your InvoiceNinja node.
I made a little demo workflow to illustrate:
Notice how you can preview the individual items with these little arrows:
Was the ‘manual’ node introduced in a more recent version? Anyway, I plan to update my n8n instance to version 1.50.1 in the next days.
No preview from “WC order created” node
Unfortunately, as you can see in my screenshot from my initial post, the expressions for fields “Cost” and “Service” are red. I suppose that this is because my “WC order created” node is 4 nodes back. Is that a known bug? Opposed to that I can preview the expression from the (directly) previous node. See screenshot.
the ‘WooCommerce Input’ node was just to simulate your WooCommerce node. All you need to do is to insert a Split-Out node in between your WC node and InvoiceNinja node and then reference it accordingly.
Would you mind sharing your workflow with some pinned (fake) data? I can try to fix it for you.
Thanks for your feedback. Today, I updated n8n and the issues 1. and 2. from my previous post are resolved now. So, I could successfully import your workflow.
However, this doesn’t work as expected. Instead of Invoice Ninja creating 1 invoice with 6 invoice items, it creates 6 invoices with 1 item each. See screenshot.
For this moment it’s ok as I only have 3 different products in my shop atm. But soon, it’ll be more. So, then I really need a dynamic solution.
Also, a drawback of this manual workaround is that the node always creates an invoice with 3 items. Even if there is just 1 item you can see the additional lines with empty line items which isn’t visually appealing. See the last two empty lines in the screenshot.
So, could you kindly escalate this matter to the team @ria ? Thanks a lot
Looking at your screenshots, you should be able to use the Split Out node for the line_items and then reference the item properties individually via $json.name etc.
Hi @ria,
the Split out node, as you suggested it previously, does not work as intended because it creates 1 invoice per line item (which makes me end up with 3 invoices for 3 line items) and not 1 invoice with 3 line items. Can you please check this again? It’s also reproducible with the example workflow you shared. Thank you.
You can ask ChatGPT (would recommend GPT4o) to create the code for the Code node for you with a prompt similar to this:
Please create javascript code that takes a list of objects as input and creates a list of objects as given below:
### INPUT ###
[
{ "name": "Product 1",
"subtotal" : 1.20
...
}
]
### OUTPUT ###
[
{ "name": "Product 1",
"cost" : 1.20
...
}
]
Hi @automaze.me ,
Thank you for your suggestion. Yes, I could do that. For now I’m living with the empty lines in the invoice.
However, in the long term from my point of view it should be possible to pass an array of line items dynamically to the InvoiceNinja node’s line items. So, I think this would be a feature request for the InvoiceNinja node. Could you pass that to the team @ria ?