Return multiple json items from mysql query in "respond to webhook node"

Describe the issue/error/question

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]:

Hey @sl-tobe,

Welcome to the community :tada:

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

Hey @sl-tobe,

What was the output when you put {{$json}} into the json output as an expression?

{“message”:“Error in workflow”}

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
}
]

Can you share the output of the MySQL node?

Hello @sl-tobe , have you tried the items list node? This would spread your data property out and you would get multiple items from element within:

Here is an example mocking the database response

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?

thanks for your commitment
Stefan

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.

Here an example:

thanks i will try that
Stefan

This is still the output with ‘data’ included
{
“data”: [{
“iccidprefix”: “89312400000000000”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}, {
“iccidprefix”: “89312400000000001”,
“acct”: “[email protected]”,
“status”: null,
“spn”: null
}]
}

Now you can do {{$json.data}} on the Webhook Response node. Also remember setting the response format as Text.

Hi I tried, however the workflow completes succesfully but none is returned (void body)

Hey @sl-tobe,

Can you share the workflow that is doing that?

I have the exact same issue. Was this ever solved?

I’m trying {{$json.data}} in the Respond to Webhook expression w/ Text as the response type and it is also returning an empty response.

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.

1 Like