Ordering Results of Order API

Solved
Shopify Partner
10 0 2

Hi!

 

I'm currently building a product requires syncing a Shopify customer's orders to our database. In order to do this, I need to pull all orders using the Order API, and then every day get all the new orders that were added or updated.

 

In order to do this, I need to order the results of the Order API by "updated_at asc" and then use the "since_id" to make sure I'm pulling exactly all orders after a certain ID. I saw on an old answer on this forum that you can use the "order" argument to order the results. It seems to work, but when I use it with "since_id" it gives incorrect results.

 

A few questions:

  • What is the recommended way to order results?
  • The "since_id" description is "Show orders after the specified ID." — how do you define "after"? Is it by the "order" field? Is it by sorting the ID number?
1 Like
Shopify Partner
1838 173 601

Hi,

 

Why do you need the orders sorted by date? If it is just a matter of getting newly created or updated orders per day, you can query orders by date range for updated_at like so

GET /admin/orders.json?status=any&updated_at_min=2019-03-07&updated_at_max=2019-03-08

But if you still insist on sorting by date, you can as mentioned in the referenced post

/admin/orders.json?status=any&updated_at_min=2019-02-27&updated_at_max=2019-02-28&order=updated_at asc
I turn coffee in to code - since 1998
0 Likes
Shopify Partner
10 0 2

@KarlOffenberger The reason that I need to fetch orders sorted by date is because I only want to pull orders that have been created/updated since last I pulled. The issue arises when I combine the "order" query argument with the "since_id" query argument.

 

The specific reason I need to use "since_id" is because there could be 250 (the maximum result amount) orders with the same "updated_at" value. In order to pull all of them, and make sure I don't miss any orders, I'll need to include a since_id to paginate through the results. Any ideas on how to solve this problem?

0 Likes

Success.

Shopify Partner
1838 173 601

So pull via since_id and sort on your end in app code once all orders have been fetched. You'd anyway want results in default sort order by ID so you have the last items' ID for the next request.

I turn coffee in to code - since 1998
0 Likes
Shopify Partner
10 0 2

@KarlOffenberger you're right, that solution makes a lot of sense. I'll look into it.

 

Do you happen to know if the "order" and "page" arguments will be officially supported by Shopify? I noticed that they seem to work when I send them, but they're not listed on the API page.

0 Likes
Highlighted
Shopify Partner
1838 173 601

Unfortunately not - I do not have any insights regarding their roadmap. Your best bet would be to post a new question asking that and a staff member might offer some insight.

I turn coffee in to code - since 1998
1 Like
New Member
2 0 1

I have rest APi client  to get API data .My company is authorized  to shopify . Can someone  advise me rest API url   to get daily orders as batch . Thanks a lot 

1 Like
New Member
1 0 0

Hi

Can you send me the request URL to retrieve the order details from shopify? I need to know the complete request URL and what authentication method need to be used at the time of sending the request?

0 Likes
New Member
2 0 1

Thanks  a lot for the response . Sure I will send you  today .

0 Likes