Hi again, thanks for your help,
I already tried putting the raw data in the JSON body of the HTTP request node, and it works like a charm, so the problem is with the data that I’m sending dynamically taken from the previous node.
I realized I’m sending data inside brackets, like an array, but I need to send the data without those objects.
I tried removing the brackets with the following ways but with no luck:
I tried this code outside n8n and is working but inside n8n it gives me an error:
var json = $input.all();
var parsedJson = JSON.parse(json);
var jsonString = JSON.stringify(parsedJson[0]);
return jsonString;
or with this:
// Remove outer brackets
const jsonString = JSON.stringify(jsonData[0]);
// Output data
return jsonString;
This is the input data
[
{
"Dte": {
"datosGenerales": {
"tipo": "\"FACT\"",
"fechaHoraEmision": "\"2023-06-16T18:28:11\"",
"codigoMoneda": "\"GTQ\""
},
"emisor": {
"direccion": {
"direccion": "\"Ciudad\"",
"codigoPostal": "\"01001\"",
"municipio": "\"\"",
"departamento": "\"\"",
"pais": "\"GT\""
},
"nitEmisor": "\"107902281\"",
"nombreEmisor": "\"SOCIEDAD ANONIMA\"",
"codigoEstablecimiento": "\"0\"",
"nombreComercial": "\"SOCIEDAD ANONIMA\"",
"correoEmisor": "\"[email protected]\"",
"afiliacionIVA": "\"GEN\""
},
"receptor": {
"direccion": {
"direccion": "\"Ciudad \"",
"codigoPostal": "1",
"municipio": "\"\"",
"departamento": "\"\"",
"pais": "\"GT\""
},
"idReceptor": "\"CF\"",
"nombreReceptor": "\"Consumidor Final\"",
"correoReceptor": "\"[email protected]\""
},
"items": []
}
},
{
"items": {
"bienOServicio": "\"B\"",
"cantidad": 1,
"unidadMedida": "\"UN\"",
"descripcion": "T-Shirt Three",
"precioUnitario": "15.00",
"precio": "15.00",
"descuento": "0.00",
"total": "15.00",
"impuestos": {
"nombreCorto": "\"IVA\"",
"codigoUnidadGravable": "1",
"montoGravable": 13.392857142857142,
"montoImpuesto": 1.607142857142857
}
}
},
{
"items": {
"bienOServicio": "\"B\"",
"cantidad": 1,
"unidadMedida": "\"UN\"",
"descripcion": "Mug BHeart",
"precioUnitario": "5.00",
"precio": "5.00",
"descuento": "0.00",
"total": "5.00",
"impuestos": {
"nombreCorto": "\"IVA\"",
"codigoUnidadGravable": "1",
"montoGravable": 4.4642857142857135,
"montoImpuesto": 0.5357142857142856
}
}
}
]
and this is the expected output data:
{
"Dte": {
"datosGenerales": {
"tipo": "\"FACT\"",
"fechaHoraEmision": "\"2023-06-16T18:28:11\"",
"codigoMoneda": "\"GTQ\""
},
"emisor": {
"direccion": {
"direccion": "\"Ciudad\"",
"codigoPostal": "\"01001\"",
"municipio": "\"\"",
"departamento": "\"\"",
"pais": "\"GT\""
},
"nitEmisor": "\"107902281\"",
"nombreEmisor": "\"SOCIEDAD ANONIMA\"",
"codigoEstablecimiento": "\"0\"",
"nombreComercial": "\"SOCIEDAD ANONIMA\"",
"correoEmisor": "\"[email protected]\"",
"afiliacionIVA": "\"GEN\""
},
"receptor": {
"direccion": {
"direccion": "\"Ciudad \"",
"codigoPostal": "1",
"municipio": "\"\"",
"departamento": "\"\"",
"pais": "\"GT\""
},
"idReceptor": "\"CF\"",
"nombreReceptor": "\"Consumidor Final\"",
"correoReceptor": "\"[email protected]\""
},
"items": []
}
},
{
"items": {
"bienOServicio": "\"B\"",
"cantidad": 1,
"unidadMedida": "\"UN\"",
"descripcion": "T-Shirt Three",
"precioUnitario": "15.00",
"precio": "15.00",
"descuento": "0.00",
"total": "15.00",
"impuestos": {
"nombreCorto": "\"IVA\"",
"codigoUnidadGravable": "1",
"montoGravable": 13.392857142857142,
"montoImpuesto": 1.607142857142857
}
}
},
{
"items": {
"bienOServicio": "\"B\"",
"cantidad": 1,
"unidadMedida": "\"UN\"",
"descripcion": "Mug BHeart",
"precioUnitario": "5.00",
"precio": "5.00",
"descuento": "0.00",
"total": "5.00",
"impuestos": {
"nombreCorto": "\"IVA\"",
"codigoUnidadGravable": "1",
"montoGravable": 4.4642857142857135,
"montoImpuesto": 0.5357142857142856
}
}
}