A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I want to fetch all orders between date range using Shopify REST API
( I used nodejs package : https://github.com/Shopify/shopify-api-js )
But I got wrong result.
This is code example.
const created_at_min = "2023-03-07 00:00:00.000"
const created_at_max = "2023-03-07 23:59:59.000"
const orders = await shopify.rest.Order.all({
session: session,
status: "any",
created_at_min: created_at_min,
created_at_max: created_at_max
});
console.log(orders.length) /// 25
In this case, total orders count is 25. this is wrong value.
When I tried to use another method, the result is correct.
const created_at_min = "2023-03-07 00:00:00.000"
const created_at_max = "2023-03-07 23:59:59.000"
const ordersCount = await shopify.rest.Order.count({
session: session,
status: "any",
created_at_min: created_at_min,
created_at_max: created_at_max,
});
console.log(ordersCount) /// count: 58
I can not understand why the same date parameters return different results.
Please help me. Thank you.
Hey there,
I am not familiar with that package but the queries that it generates should be the same. But to be on the safe side I would suggest to use something like postman to test your queries.
I just tested this making the same request to the count.json and the orders.json endpoints with exactly the same parameters and the count and number of orders returned were the same.
Can you log into the shop and try this url:
To reduce the amount of data returned I am only returning the ID of the order.
https://[shopdomain].myshopify.com/admin/api/2023-01/orders.json?status=any&created_at_min=2023-03-07 000:00:00.000&created_at_max=2023-03-07%2023:59:59.000&fields=id
and then try the following: