In my first project with N8N I am at the final step. I have a json response from a licensedistributor. The json response is with some customerinfo and also an array (Charges) which have a dynamic numbers of items with description which the customer consumes. Some have just 2-3 items, but some also have 10-15 items.
n our api to our ERP-system I can create order pr. each customer by combing the customerid, But my challenge is to fill the with the content from the array for each customer. One line for each item. Cost, Price quantity and description is what the erp-api want.
Anyone have some idea how to fill in this information dynamically?
The problem as I see it is in expression preview I just see the first customer which has 2 items. I can just drag their item to the order id, since all orders will then just be with these values and noe be correct.
I think I am into something here, but the api wont create the orders, so not quite there yet with the variables…
Hi @frankemann, welcome to the community!
In n8n every node runs once per item. So your first approach with {{ $json["customerId"] }}
was correct here. This would take the customer ID of each item and send it to your ERP. To be able to help you a little better, would you mind doing the following:
- Add your workflow here. It will not show any sensitive data, so don’t worry. This will help to understand your context a little better.
- Are your getting an error message from your ERP? If so, what error do you get?
- What ERP are you trying to send the data to?
Hi!
- i will try to create som mock data in the same structure and paste a workflow here.
- I get error, but thats becase I try to use an item(?) from the Charges array as a variable. The problem is it will pick the index (0) insted of looping through every item for the customer. Some have 2 items in the array other has 15 items etc.Not sure how I can get it to loop through the array and insert the variables between the <(Invoicerow>. for each item.
- 247sevenoffice.
My guess is perhaps i should use a Code-node or Set to actually try to create a body output with som pre-text like you see in the picture and the items variable (the green marks) in the screenshot and then pass this body to the http request which gets send to ERP?
If I only uses the customerID and do the other parts manually the http request to the ERP creates one invoice for each customer so we are pretty close.
Just those items in the arrays we need to get into the in the body of the http requiest to erp…
Here is a Function code with a sample json from our respond. Here is for 2 customers, I have changed their name and the cost/sales prices naturally.
So the questions is how I can create a bodu output, 1 for each customer which can be send as body in a final http request. As you can see from the first post its the part saying VALUEI am having hard to insert the items for the customers.
@frankemann If I’m understanding correctly, you’re trying to send one request to the API per charge? In that case I think the code node works best for your indeed. Like below:
On another note, I’m not sure if the 24sevenoffice API supports REST calls. But not an expert on that
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.