[admin/api] events.json - how retrieve latest events (order by created_at) seems not working

Highlighted
New Member
13 0 0

Hello,

Im trying get latest events but i'm unable to change order - so when I limit for 250 PCS - I got responded with oldest not newest.

Im  using:
SHOPIFY_API_VERSION=2020-07

and query REST via:

$shop->api()->rest('GET', '/admin/events.json',['limit' => 250, 'order' => 'created_at desc']);

 

and response  (expected first element  of array to be dated from 06.24 but here is oldest.

(am I doing that query order created_at dec wrong way?)

 

Screenshot 2020-07-31 at 13.11.10.png

 

regards

0 Likes
Highlighted
Excursionist
26 4 3

Hello,

there is two solutions for you.(if i am not wrong you need new orders but shopify rest api give you old)

one solution is paging please try pagination in your request.

second solution is "since_id" tag in your request.(since_id always give you orders after mentation since_id value)

please tell me which is good and if you need more info please tell me which one is good for you.

thanks

0 Likes
Highlighted
New Member
13 0 0

Thank You for quick reply,

We are talking about events:

https://shopify.dev/docs/admin-api/rest/reference/events/event?api[version]=2020-07

 

Problem with them -  they are triggered by multiple  actions and quickly go to crazy amount of records,  on my developing store after adding couple fake data I got event count of

 

count" => 8915

 

Fetching all of them require using pagination and for that 9000 require making 36 requests.

So i really what i need is just order_by via id or date and limit  for example 100 records.

For now I test using data:

 

 

$shop->api()->rest('GET', '/admin/events.json',['limit' => 250, 'created_at_min' => '2020-07-22 12:30:00+00:00']);

 

 

 but problem witch created_at_min will not return any results if they not existing in that period,  so i should change date backward until I get 250 results making another requests.

 

I hope You understand my problem and give other advice?

 

0 Likes
Highlighted
Excursionist
26 4 3

hello,

Do you know if your client is encoding the URL before it's sent? When a timezone contains the + symbol, it needs to be encoded when sent as part of the URL, otherwise it's interpreted as a space which causes the timestamp to be ignored.

An easy way to test is to manually replace + in your URL with the encoded version %2B and try sending the call again.

/admin/events.json?created_at_min=2020-06-11T09:39:24%2B02:00

If you get the expected results, this suggests your client wasn't encoding the URL previously.

And

why not use since_id. when you get your response save your last id in Db and next just start from that id.

i will prefer since_id more then date but in my case created_at_min is also worked good.

Thanks

 

0 Likes