Discussing APIs and development related to customers, discounts, and order management.
I am trying to retrieve a list of orders using this REST API endpoint.
Below is a little snippet code of what I am doing.
sdk.rest.Order.all({ session, ids: orderIds.join(","), })
As you can see, I am creating a comma-separated string of order IDs as instructed by the API doc. However, the orders I get in the response is not deterministic. Sometimes it is 0 orders sometimes it has some orders. When I retrieve the orders using individual fetch, I can get them no problem every time.
Could someone explain to me what is happening? This is causing some major production issues for me.
Hello @jimin-genie
Can you try by below code ?
const orderIds = [/* Your array of order IDs */];
// Make sure the 'session' variable is properly initialized before this point
// Convert the array of order IDs to a comma-separated string
const idsString = orderIds.join(",");
// Use the SDK to retrieve the list of orders
sdk.rest.Order.all({
session,
ids: idsString,
})
.then((response) => {
// Handle the response here
console.log(response);
})
.catch((error) => {
// Handle any errors here
console.error(error);
});
If My solution doesnt work for you , I can assist you with this by examining your code. Once you approve the collaboration, we can proceed with fixing the issue for you.
I'm hoping someone from Shopify will chime in on this because I've started noticing this as well. I have full permissions to read all orders, yet I'm getting different results from the 2 versions of the Admin REST API GET endpoint for Orders:
Sending this request to GET Orders returns 0 results, no errors, and a 200 response:
admin/api/2022-10/orders.json?ids=5096762704056
Sending this request to GET Orders returns the expected order:
admin/api/2022-10/orders/5096762704056.json
In both cases I'm providing no other filters, yet the endpoint that takes a list of ids seems to either
Hey there @ktbishop,
The GET orders endpoint (admin/api/2022-10/orders.json?ids=5096762704056
) returns open
orders only by default.
If the orders you are specifying by ID are either closed or cancelled, they will not return, even if an ID is specified in the parameters. I would recommend adding in &status=any
to your query.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thank you for the response and for pointing that out! Would it be possible to have that mentioned at the top level description for the endpoint? The status param is part of the "hidden fields" that are collapsed by default, and I feel like that's a pretty important detail being hidden as a small blurb next to a hidden param.
Happy to pass that feedback along to our Developer Documentation team!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog