I need to capture an array of items and use them inside the JSON request body of the HTTP module:
[
{
"Id": "21"
},
{
"Id": "22"
}
]
The items need to be added to the http request body in JSON format (exactly as they are shown now, but without the array brackets), without clobbering the JSON that I already have in the request body.
Currently if I try to reference inside the request body I can only get one value at a time.
The reason for this is I am trying to add new line items to an existing QuickBooks invoice, and the current QuickBooks node does not support adding line items.
Unfortunately, the QuickBooks API also requires you to preserve the existing transaction IDs in the request body otherwise they get deleted and replaced with the new one - so I am also not able to loop my http request.
Whatās the best way to accomplish this? Also, if anyone knows of a better way to accomplish adding new line items to a QBO invoice using N8N please share.
What is the error message (if any)?
Please share the workflow
Share the output returned by the last node
Information on your n8n setup
n8n version: 0.198.2
Database youāre using (default: SQLite): Postgres
Running n8n with the execution process [own(default), main]: own
Running n8n via [Docker, npm, n8n.cloud, desktop app]: k8s
It looks like you have 2 items so you could use a Code node to merge them into one object, Do you need to send a string like what you have in the set node (without the []) or a json object?
A link to the API doc you are following may be handy if you have it.
Thanks @Jon - this is just mock data but the real data is being pulled from the existing invoice using the QuickBooks node.
Basically what I need to do is preserve the ID of the existing line items and add them into the request body along with the rest of the data Iām sending.
So I take it then you are doing the full update, Is it this part you are trying to preserve? or is it just an ID? knowing which field you are using will be a big help.
With the Set node, Iāve got exactly the output and data preserved that I want now.
However Iām still having trouble merging the new data in. I am assuming a code node is best for this but JavaScript is not my strong suit.
What I need to do now is 1) Loop through a list of input values 2) Construct them using the JSON expected by the QBO API and 3) Append them to the output of the Build QBO Request node I shared.
Any idea how I can stop this from happening? I just need the raw output of the entire previous node to populate this field without adding the extra json key.
@joeldeteves happy to hear you found a solution. Prior to discovering the Item Lists node, can you remember what you thought you were looking for?
Basically what search term/ how were you thinking about the problem prior to finding Item Lists node? We can add alias search terms to any node, so would be helpful to know. This way we can make it more discoverable for others in future
Check customer subscriptions in our CSP partner portal
Add subsriptions to the invoice (matched by SKU)
Email invoice to the client
The main challenge was rebuilding the QBO Item List - QuickBooks API uses an array to store this information and the only way to āaddā an line item is to capture the existing line items and include them in your query, otherwise all the existing line items are overwritten / removed.
Therefore I needed to capture that data, combine it with my new data and re-construct it into JSON for the final HTTP request.
I guess I was originally trying to do this using a SET node, when in fact I needed several SET nodes and an Item Lists node using the aggregate feature to combine them.
I think the best solution would be to update the QuickBooks node to have an āAdd Line Item to Invoiceā feature - that would eliminate a ton of the logic being used here.
But overall, I guess you would want to add the search term ācombineā and āaggregateā to the Item Lists node - those are definitely things that are useful when pulling data from multiple sources and re-constructing into a single field.