admin api can't get more than last 500 orders

derekCyfe
New Member
1 0 0

I'm working on creating two reports.

  1. daily orders for any date range given by our users (https://shopify.dev/docs/admin-api/rest/reference/orders/order here I see we can only get the last 60 days)
  2. daily sales from orders for any date range (we only expect to get 60 days worth of data because of same reason mentioned above)

We highly prefer to not have to store all orders for our users as there's more room for error which will make inconsistencies between our product and yours. We essentially just want to mimic the reporting functionality of /admin/dashboards of a shopify account. Specifically we're interested in mimicking the data shown in Total Sales and Total Orders. Our customers don't want to only have to look in their Shopify dashboard because we report on other analytics their business might find useful outside of shopify.

 

We are having trouble successfully getting more than 500 orders using /admin/api/2020-04/orders.json?status=any endpoint. I've tried with and without status parameter as well as using created_at_max and created_at_min. I've also tried paginating using the since_id parameter as well as using the response header which links to the next data set.

 

According to API documentation the response header link is the preferred way to currently paginate, so I will go over our issue doing this.

The first endpoint we hit is /admin/api/2020-04/orders.json?status=any&limit=250 (I've tried without status param and same result). The response successfully gives us the next link which we use to query another 250 set of orders. At this point everything is working as expected, but when we use the new link header (yes it says rel="next") in the following request (this would be 3rd request) we get a response with orders that are identical to what we received from our first response. Then when we grab header link and make another request we get the same values as second request. Paginating is essentially looping us through the first 500 orders over and over again. 

 

I see there is also the endpoint /admin/api/2020-04/orders/count.json but it doesn't give the daily breakdown for the date range given. (This would be a very useful addition) Since we have customers who make anywhere from 0-10,000+ orders a day, having to make an API request for each day seemed like it was unneeded and a bad practice for using the API endpoint. Also, this endpoint wouldn't help with #2 above of what we're trying to accomplish. 

 

Is it known you can't paginate more than 500 orders without being looped? I can put my code below for proof and then it can be tested with as needed. 

 

$obj = array();
	$page = 1;
	$continue = true;
 
    $endpointo = "https://<shopifystore>.myshopify.com/admin/api/2020-04/orders.json?limit=250";
 


	while($page <= $pages && $continue)
	{
	    $continue = false;

		$output = process_curl(array(
			CURLOPT_URL => $endpointo,
			CURLOPT_HEADER => true,
			CURLOPT_TIMEOUT => 30,
			CURLOPT_SSL_VERIFYPEER => false,
			CURLOPT_HTTPHEADER => array('X-Shopify-Access-Token: '.$token),
		));

		if(!empty($output))
		{
            $lines = explode("\r\n", $output);

            foreach($lines as $index => $line)
            {
                if(strpos($line, 'link:') !== false && strpos($line, 'rel="next"') !== false)
                {
                    $endpointo = $line;
                    $endpointo = substr($endpointo, strpos($endpointo, '<')+1);
                    $endpointo = substr($endpointo, 0, strpos($endpointo, '>'));

                    $continue = true;
                }
                elseif($index === count($lines) - 1)
                {
                    $obj[$page] = json_decode($line);
                }
            }
		}
		else
			return false;

		$page++;
	}

	return $obj;

 

 

 

0 Likes
TLett
New Member
2 0 0

I'm having the same problem using 2021-01; less than 500 depending on whether I set a limit lower than 250 in my query string. 


My setup is a private app synching shopify sales down to brick and mortar store database, which is the system of record for inventory management. Normally this won't be a problem, as the synch process will happen multiple times daily and bump the updated_at_min value with every synch, but based on some cursory testing, the orders are not sequenced by the updated_at value, so there isn't a way to guess the missed orders, and bumping my updated_at value to the max returned timestamp means they're just missed.

Is there a better place to report the bug?

0 Likes