In all of the actions that are carried out I would like to send an email to different users detailing what is contained in the order.
The problem being that the number of products is not always the same and therefore I do not see how to combine the different products of the order in an email.
I do not know if I am clear in my request.
Do you have any idea how I might do this?
Can you post the data you receive so we can play with it?
You should be able to just loop over the array “line_items” and create a row for every entry, using the data you want to display (name, quantity, total?).
I’ve put a quick example workflow together that uses your example data and writes it into a single string field (which you can then send out via email). It uses some JavaScript logic:
The initial Function node converts the example dataset you have provided in a valid n8n data structure consisting of multiple items (one for each of your line items).
In the second Function node, we’re building a single string which you can use in your email. This script essentially just iterates over all input items and appends to our result string message.
Example Workflow
And this is the resulting email:
Is this what you had in mind?
Edit: This would work fine while your workflow only processes a single cart at a time. If there are multiple carts we might need to adjust our logic slightly. It would actually become simpler, since we could just iterate over each line item directly and wouldn’t need to convert the line items into n8n items beforehand (but the data structure would be harder to read).
Ah yes, I think that might have been some mixup earlier
I definitely prefer the preformatted text as it will prevent all formatting from being applied. Either using this button or by manually putting three backticks ``` before and after my code: