Hello guys, I’m trying to prepare my automation to be smart when I have different numbers of items products on a sale and create a sale to post on other api.
Some times I’ll get 1 service, other time l’ll get 2 services and some I can get until 10 services to send to Pipedrive API.
@Rodrigo_Pereira1 , you need to add “Items List” node to aggregate your services. Then it will not matter how many of the items you have - one or more. Here’s an example.
@Rodrigo_Pereira1 , if I understood you right, the latest issue you report is not with Item Lists bit with the expressions you use. There are tons of suggestions how to fix it in this forum (try to find them). The most common solution is to use first() instead of item (if there is only one item). Here’s the docs describing the usage, Output of other nodes | n8n Docs.
@Rodrigo_Pereira1 , without seeing the actual data in “Estrutura” node it hard for me to tell you what your expression should look like when you reference the nodes prior to the previous one. However, the link I provided how to reference the nodes still stands and it should work.
Perhaps you need to combine the data from “Estrutura” node and the List Items. Again, I do not know what your data looks like and what it should look like for your final POST request.
As “Estrutura” node has 2 items in the image, does it mean you need to make 2 POST calls in HTTP Request node or it needs to be 1 request with 2 items presented in the array? Perhaps you can show what the data in “Estrutura” node is (and maybe other nodes) and how it should be presented to be used in the HTTP Request node, then I could guide you with how to transform it.
Anyway, assuming you need to combine the data from “Estrutura” node and the List Items (so that HTTP Request does not need to reference “Estrutura” node), here’s an example how you could do it.
@Rodrigo_Pereira1 , you still seem to reference the previous nodes. The whole idea behind using Merge node is that you get rid of $('<NODE>') and use just incoming data in the final HTTP Request. That is they all would be $json.<peroperty>. This will resolve your latest problem but you might want to update your references as it make it easier to maintain.
As for the error “JSON parameter need to be an valid JSON”, it looks like “Using JSON” option dose not like complex JSONs. However, this could be overcome by mapping the values manually with “Using Fields Below” option.
In that case, the offending property, namely "services" will have just value {{ $json.services }}. Nested part of JSON a bit more complex. If you have something like this
Then the field will be payment.installments[0].number and it’s value just 1. Similarly the “value” property would have to be presented as payment.installments[0].number with value “something”.
This depicted in the node below
Alternatively, you can introduce Set node between Merge and HTTP Request. This Set node would have all these manually set fields and the HTTP Request would have only one value, {{ $json }} with “Using JSON” option:
@Rodrigo_Pereira1 , actually I figured it out how to make “Using JSON” option work with your configuration. You need to make the whole JSON as an expression. That is,