0

I have integrated Shopify Order API. Reference Link

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

Yash
  • 1,446
  • 1
  • 13
  • 26

1 Answers1

0

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 and solution 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).

Yash
  • 1,446
  • 1
  • 13
  • 26