Can I return more than 50 items from the listOrders function #ask-the-community

Question:
Can I return more than 50 items from the listOrders function Ask the community

Product:
Wix editor

What are you trying to achieve:
I need to get a list of all members who have a paid payment plan. The function works, but only returns 50 items. I need to return all the members, and there are more than 50. How can I do that?

What have you already tried:
export const myListOrdersFunction = webMethod(Permissions.Anyone, async () => {
let id = “”;
let mbr;
const listedOrders = await orders.listOrders();
//return listedOrders;
for (let i = 0; i < listedOrders.length; i++) {
id = listedOrders[i].buyer.memberId;
ids.push(id);
}
for (let i = 0; i < listedOrders.length; i++) {
console.log(“ids[” + i + “)=”,ids[i]);
}
});

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

Hi, Ron_Carran !!

I’m not sure if this code will work, but for now, please try it like this. If it works with a setting of 100, you might want to try increasing it to around 1000. :grin:


// ...

const paging = { limit: 100 };
const listedOrders = await orders.listOrders(null,null,paging);

Thanks, onemoretime,
Good try, but the error says no more than 50. You’d think there was a workaround. I don’t understand why a seemingly arbitrary limit of 50 was put on this function. I’m sure many sites have more orders that 50.
Ron

OneMoreTime, was almost on the right track! Almost!

So what is the issue? → YES → YOU CAN’T SETUP MORE THAN 50-ITEMS PER CALL!!!

BUT!!! —> What about —> SKIP ???

Let us investigate the API for listOrders…
—> List Orders | Velo

What do we have here???


Ok → Confirmed! This we already know now!

But what’s this?


Yes, some kind of pagination function, already mentioned by → OneMoreTime

Let’s open → PAGINATION-INFO…

Ok, now we got it → we can do multiple calls using SKIP to get more then 50-items (of course not with one call, but by generating multiple calls).

And if it comes to multiple calls → maybe we also should think about → PROMISE-ALL-FUNCTION!

----> Better way to get multiple values out of a promise? (getmember) - #2 by moran-frumer

The default was set to 50, so I thought the specifications might have changed, but it seems the limit is still 50. The last time I tried, it was capped at 50 as well. Such limitations are likely in place to prevent accidental or intentional spamming of requests, which could essentially turn into a form of attack. As the most skilled ninja in our community says, it seems necessary to retrieve items in pages of 50 by using some form of iterative process, incrementing the skip count by 50 each time, and then combining the retrieved items into a single array. As a Japanese person, I fully—or rather, almost—support the ninja’s advice! :flushed:

1 Like

That’s actually a good idea. I had thought of something like that, but didn’t put together a way to do it successfully. I’ll give it a try. Thanks to you and your ninja!

1 Like