Getting more then 250 orders using api

Highlighted
Tourist
9 0 0

Hi 

I am trying to create an array of orders for a specific date range. Let's say there are 300 orders. The first set gives me 250 orders. But after that when I get the last order of that array and uses it of the next loop I am again getting an array of 250.

I am doing something

$orders_obj_url = 'https://XXXXXXXXXXXXXXXX.myshopify.com/admin/api/2019-10/orders.json?status=any&limit=250&created_at_min='.$orderfm.'T00:00:00&created_at_max='.$orderto.'T23:59:59';
$orders_content = @file_get_contents( $orders_obj_url );
$orders_json = json_decode( $orders_content, true );
$orders = $orders_json['orders'];

if(count($orders) == 250) {
    $lastorderarray = end($orders_json);
    $lastorderno = $lastorderarray["number"];
    nextordrs($lastorderno);
}

function nextordrs($lastorderno) {
    $orders_obj_url = 'https://XXXXXXXXXXXXXXXX.myshopify.com/admin/api/2019-10/orders.json?status=any&limit=250&since_id='.$lastorderno.'&created_at_min='.$orderfm.'T00:00:00&created_at_max='.$orderto.'T23:59:59';
    $orders_content = @file_get_contents( $orders_obj_url );
    $orders_json = json_decode( $orders_content, true );
    $next_orders = $orders_json['orders'];
}

I was trting to get the next batch of order and combind the array for the report.

As par, my understanding I should get order 1 to 250 from the variable $orders and 251 to next 300 from variable $next_orders. 

nextordrs() is giving me older orders instead of the newer orders. 

 

Can anyone please help me with this?

Thanks.

 

0 Likes
Highlighted
Shopify Partner
1337 154 236

As the name of the parameter implies - since_id - is the value of order id not order number, so you just need to adjust the line to read the id of the last order received in a batch like this:

$lastorderno = $lastorderarray["id"];

 

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
0 Likes
Tourist
9 0 0

I have tried that but when I used id instead of number. It is returning empty array " array(0) { } " . 

0 Likes