in the workflow i perform a query on mysql table returning 78 items
These items must be returned as response to a webhook
I can only select “return first item” or select an expression.
I cannot get it to work to return all 78 items in json array
What is the error message (if any)?
n/a
Please share the workflow
Share the output returned by the last node
Information on your n8n setup
n8n version:
Database you’re using (default: SQLite):
Running n8n with the execution process [own(default), main]:
Running n8n via [Docker, npm, n8n.cloud, desktop app]:
Have you tried setting the respond to webhook node to use JSON and set the data to an expression and using something like {{$json}} to see if that works?
Hi I dont know how to do so. But i worked around it temporary by including a node ‘item list’
to aggregate all output in one item (which is not preffered). Can you provide an example how to just list array of items without aggregation (without ‘item list’ node)?
thanks
Stefan
This is what currently comes out (with help of itemlist node)
{
“data”: [{
“iccidprefix”: “89312400000000000”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}, {
“iccidprefix”: “89312400000000001”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}]
}
===========
this is what I´ d prefer:
[
{
“iccidprefix”: “89312400000000000”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}, {
“iccidprefix”: “89312400000000001”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}
]
The point is that the output from mysql query is exactly like this
[
{
“iccidprefix”: “89312400000000000”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}, {
“iccidprefix”: “89312400000000001”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}
]
but i cannot get that output in the 'response to webhook "
referring to {{$json}} as expression in 'response to webhook" is throwing an error (as mentioned earlier in this thread). Does the response need to be ‘fixed’ or an ‘expression’, and if an expression, how would the expression that look like?
Hi @sl-tobe , misunderstood your issue initially. I think you could use the .reduce() function in javascript. It would collapse all your items into one.
The error you receive it is related to the fact that the webhook node is meant to be executed only once and by having multiple items as input it would be executed multiple times, hence the error.
Also, I’ve set the Webhook response node data as text. It wouldn’t have accepted the output otherwise because of not being an JSON object.
I solved this. The solution is in this post: More then one item from the "Response Webhook" node. You need to use the Item Lists block to combine all of your items into one item. Then you can return everything in the Respond to Webhook response.