简体   繁体   中英

How to fetch orders between date range using Shopify REST API?

I want to fetch orders between two dates using Shopify REST API, so-far I'm trying to achieve this via below endpoint

/admin/api/2020-07/orders.json?status=any&created_at_min=2022-04-14 00:00:00.000&created_at_max=2022-04-14 24:00:00.000

It returns total 2134 orders also it includes orders of 2022-04-15 But as per Shopify the total orders of 2022-04-14 are 2141.

However, when I consume the below mentioned order count endpoint using the same date range, it returns the correct count, just as Shopify shows. 2141

/admin/api/2020-07/orders/count.json?status=any&created_at_min=2022-04-14 00:00:00.000&created_at_max=2022-04-14 24:00:00.000

I am unable to understand why the same date parameters return different results.

Please advise how to achieve this. Thank you!

I also tried this case like you

(1) about API count orders

/admin/api/2020-07/orders/count.json?status=any&created_at_min=2022-04-14 00:00:00.000&created_at_max=2022-04-14 24:00:00.000

returns 2141 as true

(2) about API get orders

/admin/api/2020-07/orders.json?status=any&created_at_min=2022-04-14 00:00:00.000&created_at_max=2022-04-14 24:00:00.000

returns only 2134 which is false

Cause: because since_id is missing in first call api, Orders are not sorted by ID in ascending order

Solution: Add params since_id=0 with the first API call (2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM