I have a json results that I would like to create an invoice with a custom API via the HTTP node.
The problem is that the number of line items always varies and I would like to input each item on a new row based on the number of items received by the first data.
Each new item is created with this name on the API newitems[0][description] as you can see on the http node on the workflow I shared.
Do not think you can send multipart/form-data dynamically using the HTTP node. You can do an HTTP request from the function node and that should do it.
const rq = require('request-promise-native');
let values = [];
for (const item of items) {
values.push({ description: item.json.value })
}
await rq({
method: 'POST',
url: 'https://webhook.site/8df892df-f741-431b-98dd-51377fc0d35d',
form: {
firstname: 'whatever',
lastname: 'asasas',
newitems: values,
//add all other required parameters
}
})
return [
{
json: {}
}
]
Make sure you allow the use of the external library using the env variable EXPORT NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native. I used request-promise-native but you can use Axios as well.
Ahhh, If you can send the payload as JSON, you do not need the function node. You can do it with the HTTP node. Just use a function node to create the body and then reference it in the HTTP node. It should look similar to the one below.
let values = [];
for (const item of items) {
values.push({ description: item.json.value })
}
return [
{
json: {
firstname: 'whatever',
lastname: 'asasas',
newitems: values,
}
}
]
I just have one more request that I really need you help if you can help me to complete this workflow.
I have these results that I would like to modify. What I need is to remove the “1x” and the characters after “/ Matte - _GDP8794.jpg” and then after the first item add a + sign and separate all the next items with a comma.
Like this:
Fotos impresas 8 x 10 + Fotos impresas 6x8, Fotos impresas 5 x 7 and so on. Is it possible?
[
{
"pedido": [
"1x Fotos impresas - 8 x 10 / Matte - _GDP8794.jpg 1x Fotos impresas - 6 x 8 / Matte - _GDP8793.jpg 1x Fotos impresas - 5 x 7 / Matte - _GDP8792.jpg 1x Foto en formato digital - _GDP8790.jpg"
]
}
]