What's the best frequency for fetching Shopify orders via API?

I’m working with the Shopify Orders API and running into some timing issues. My current setup pulls orders every 10 minutes using the created_at_min parameter to get new orders since the last check.

The problem I’m facing is pretty weird. Even when I set the time filter to only get orders created after a certain time, I’m still getting older orders that should have been filtered out. For example, if an order was created at 11:00 AM and my next API call happens at 11:20 AM looking for orders after 11:00 AM, that 11:00 AM order still shows up in the results.

I’ve set up timezone handling in my code to match the shop’s timezone settings. Here’s what my implementation looks like:

$previousRunTime = $this->getLastExecutionTime(); // Get timestamp from database
// Set current timestamp for database storage
$currentTime = new DateTime(date("Y-m-d h:i:s"), new DateTimeZone('UTC'));
$currentTime->setTimezone(new DateTimeZone('US/Pacific'));
$executionStart = $currentTime->format('c');

// Get orders from API
$orderData = $shopify->Order->get(array('status' => 'any', 'created_at_min' => $previousRunTime));
// ... processing logic here
// Save current execution time
$this->saveExecutionTime($executionStart);

What would be the optimal interval for calling the orders API to avoid these timing conflicts?

Hit this exact issue building an order sync last year. You’re mixing timezone conversions - converting to Pacific but Shopify wants UTC timestamps for API calls. Your $executionStart gets timezone-converted when you should stick with UTC throughout. Also, there’s usually a delay between order creation and when it shows up in the API, especially during traffic spikes. I added a 2-3 minute buffer to my created_at_min parameter to catch orders still processing. So if my last run was 11:00, I’d query for orders after 10:57. Your 10-minute frequency works fine, just fix the timezone handling. Keep everything in UTC and only convert when displaying to users.

The issue you’re encountering is likely related to Shopify’s eventual consistency, rather than the frequency of your API calls. It’s common for orders to appear in subsequent API calls even if you’ve set appropriate time filters. Rather than changing your fetch frequency, consider implementing idempotency checks in your logic. By storing the order IDs that you’ve already processed, you can prevent duplicates in your results. A fetching interval of 5 to 15 minutes is generally effective; your current 10-minute schedule is appropriate. However, ensure that you are sending UTC timestamps in your API calls, as Shopify’s API requires that format to avoid unexpected results.

your timing logic’s off. shopify’s API gets weird with timezones - use updated_at_min instead of created_at_min because orders get modified after they’re created. try bumping your interval to 15-20 minutes so the system has more room to breathe.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.