Return multiple items with webhook response

Hi all, I am trying to return the result from an SQL query using a webhook as JSON but can’t find a way to return more than the first dataset from the results. I have 10 to return.

The JSON Option explicitly limits the output to the first item only. I already thought about using a “SET” block to capsule the whole JSON from the MYSQL and make it appear as the first item but had no luck with that so far either.

Has anyone an idea on how to archive this?.

Thanks for your input.

Hinnerk

Hey @hinnerk,

Welcome to the community :raised_hands:

Do you have an example of the output from your SQL node? I can use that to pop a quick example together for you, One thing to think about is if it is multiple items the node will try and run once for each which is likely not going to work so I suspect it may need a function node to merge all the items into one response.

Hi Jon, thanks for the welcome!

sure, that makes sense and was what I thought about when trying to fiddle a workaround making the whole set look like it is only one item.

At the moment I only select * from mytable and there are currently just three datasets for testing… no worries to share any of them :slight_smile: I will change the query later to only return a defined subset. So I would be perfectly happy if the webhook returns exactly the json output as follows:

[
{
"id": 1,
"postid": 123,
"blogid": 456,
"authorid": 999,
"firstseen": "2022-06-27T19:30:36.000Z",
"feature": null,
"imgurl": null,
"title": "One line of Text",
"abstract": "about 2k of characters that form an abstract",
"permalink": "https://somesite.com/and-some-path-to-go"
},
{
"id": 2,
"postid": 532,
"blogid": 234,
"authorid": 999,
"firstseen": "2022-06-27T19:30:36.000Z",
"feature": null,
"imgurl": null,
"title": "One line of Text",
"abstract": "about 2k of characters that form an abstract",
"permalink": "https://somesite.com/and-some-path-to-go"
},
{
"id": 3,
"postid": 163,
"blogid": 436,
"authorid": 399,
"firstseen": "2022-06-27T19:30:36.000Z",
"feature": null,
"imgurl": null,
"title": "One line of Text",
"abstract": "about 2k of characters that form an abstract",
"permalink": "https://somesite.com/and-some-path-to-go"
}
] 

Feels dirty but does the trick. – Wrapping the Array in an Array so it gets returned as “the first item” and unwrap the data on client side again.

Improvements welcome, I am really bad at Javascript…

var result = [];
result.push(items);
return result;

Thanks @Jon for pointing me to try using a function here.

1 Like