php - Shopify Order API call Interval
I have integrated Shopify Order API. Reference Link (https://help.shopify.com/en/api/reference/orders/order#index)
Currently fetching orders based on
created_at_min field. I am calling API in every 10 min of interval like if last API called at 11:00 AM so the next API will fetch order whichever is created after 11:00AM and script will keep time of the current API call.
Timezone also set in my script code based on shopify timezone.
Issue is if order created at 11:00 AM and I am trying to fetch order which are created after 11:20 AM still 11:00 AM created orders are coming.
What should be the ideal time interval to call order API?
My code is below:
$lastScriptRun = $this->selectLastRun(); // Fetching last run time from database // Here creating current time to store in database $estDate = new DateTime( date("Y-m-d h:i:s") , new DateTimeZone('UTC')); $estDate->setTimezone(new DateTimeZone('US/Pacific')); $scriptStart = $estDate->format('c'); // Fetching orders $orders = $shopify->Order->get( array('status' => 'any', 'created_at_min' => $lastScriptRun) ); ....... // [after some code] // Updating last API call time into database $this->updateLastRun($scriptStart);
SDK Link (https://github.com/phpclassic/php-shopify)
I found the solution.
This line was not returning UTC time properly.
$estDate = new DateTime( date("Y-m-d h:i:s") , new DateTimeZone('UTC'));
I tried with another one which found in defination (http://php.net/manual/en/function.gmdate.php) and solution (https://stackoverflow.com/questions/8655515/get-utc-time-in-php) links.
$estDate = new DateTime( gmdate("Y-m-d\T00:00:00\Z") );
Solution: Ideal time can be anything (standard 30 min to call an API I set for my Application).
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.