Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Retrieving list of orders gives indeterministic responses

Retrieving list of orders gives indeterministic responses

jimin-genie
Shopify Partner
6 0 8

 

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.

 

Replies 5 (5)

ThePixelEdge
Shopify Partner
164 16 18

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.

If helpful then please Like and Accept Solution .
Buy me A Coffee

Whatsapp :- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications


Connect with Us in Our DMs | teampixeledge@gmail.com

ktbishop
Shopify Partner
24 1 5

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 

  1. be broken or
  2. be applying some extra filters on the backend that the API docs aren't mentioning

 

Kyle B.
ShopifyDevSup
Shopify Staff
1453 239 534

Hey there @ktbishop,

The GET orders endpoint (admin/api/2022-10/orders.json?ids=5096762704056) returns open orders only by default. 


25-43-50527-79078

 

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

ktbishop
Shopify Partner
24 1 5

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.

Kyle B.
ShopifyDevSup
Shopify Staff
1453 239 534

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