Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Get Orders REST endpoint is retrieving duplicated orders,and updated_at_max param is failing

Get Orders REST endpoint is retrieving duplicated orders,and updated_at_max param is failing

alfonsohdez08
Tourist
5 1 1

I'm using this order endpoint for retrieve all orders whose status is any, and were updated in a specific date range. For instance, yesterday at 2:15 PM I used that endpoint by passing the following date range: 2019-07-21T14:00:00 to 2019-07-22T14:00:00, but I noticed that there was an order duplicated (both orders were in different pages, but when inspecting each page's response, I saw that specific order was duplicated). Also, when checking the whole result (all pages), I saw orders that were updated even after the maximum date (updated_at_max parameter) passed to the request (in this case, orders that were modified after 2019-07-22T14:00:00).

 

Why is this happening? For now the workaround that I'd take it's increase the gap time between current time when pulling, and the maximum date? (thus, the probability of fetch orders out of the date range specified would be lower, and it might help not bringing duplicated orders).

 

Thanks!

Replies 5 (5)

Visely-Team
Shopify Partner
1843 210 488

When you say orders are duplicated, do you mean you are getting 2 orders with the same order id? Also, how do you paginate through results? If you can provide examples for the exact requests you are making that might help.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
alfonsohdez08
Tourist
5 1 1

Yes, orders with the same order id (actually the same object), but in different pages. Also, for construct the pagination, first I'm calling the order's counting endpoint with the following parameters:

 

  • status: any
  • updated_at_min: 2019-07-21T18:00:00+00:00
  • updated_at_max: 2019-07-22T18:00:00+00:00

The actual request looks like:

 

admin/orders/count.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any
Now the request above retrieves me the total of orders that I'd be paginating (in my case 2177). By knowing this, I do some math for calculate how many pages I need for retrieve all these orders:
 
Pages Qty = Total_Orders/Limit

Total_Orders: Number of records returned by the request above.
Limit: Number of records retrieved by page (250).

Note: I'm applying a ceiling function to the division above, thus I'd cover all pages.
So using the formula above:
 
Pages Qty: 2177/250 = 8.708
Ceiling the result above: 8.708 ≈ 9
So the number of pages for fetch the 2177 orders are 9... I'm constructing the following requests for return all the orders:
 
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=1
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=2
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=3
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=4
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=5
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=6
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=7
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=8
admin/orders.json?updated_at_min=2019-07-21T18:00:00+00:00&updated_at_max=2019-07-22T18:00:00+00:00&status=any&limit=250&page=9
In page 6, I'm getting the order 123 (in the bottom), and then in page 7, I also get the order 123 (in the beginning).
Visely-Team
Shopify Partner
1843 210 488

What version of the API are you using? Is it 2019-04 or 2019-07? If 2019-07, I'd suggest you to switch to the new pagination based on cursor - https://help.shopify.com/en/api/guides/paginated-rest-results. Should be easy. Interesting whether you'll see the same inconsistencies.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
alfonsohdez08
Tourist
5 1 1

I'm not sure, my app is consuming the endpoint in the base "admin/{shopify_entity}", not "admin/api/{api_version}/{shopify_entity}", so I don't know to which API version is taken implicitly... Thanks for sharing the API updates, though! Sadly, Orders doesn't support the cursor-based pagination yet. Also, should I specify the API version to the latest one, and start using that one (in case I'm not using that one)?

 

I'm still curious about the duplicated orders issue (and orders out of the date range)... any technical thoughts about that?

Busfox
Shopify Staff (Retired)
628 49 110

Hi @alfonsohdez08,

 

Have you tried applying the since_id parameter to your request? If you set since_id=1, you will receive all results in order by id and would ensure the order of the data set is never shifted by having a given order's update_at date change.

 

If using GraphQL, you could also sort by the fields shown here. Note that individual records still have a chance to "change order" when sorting by a mutable field if that field changes between pages. ID. created_at or order_number would be the safest here.

 

As for making calls without specifying a version, we will always assume the oldest supported version. In this case, 2019-04.

 

Cheers,

To learn more visit the Shopify Help Center or the Community Blog.