My Business
5.5K members online now
5.5K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

Error Request contains an invalid argument when using setRegularHours

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I create some locations without problems, but when I add regularHours the error occurs.

 

I use this code

$businessHours = new Google_Service_Mybusiness_BusinessHours();
$businessHours->setPeriods($timePeriods);
$location->setRegularHours($businessHours);

The RegularHours Object looks like this:

    [regularHours] => Google_Service_Mybusiness_BusinessHours Object (
            [collection_key:protected] => periods
            [internal_gapi_mappings:protected] => Array ( )
            [periodsType:protected] => Google_Service_Mybusiness_TimePeriod
            [periodsDataType:protected] => array
            [modelData:protected] => Array ( )
            [processed:protected] => Array ( )
            [periods] => Array (
                    [0] => Google_Service_Mybusiness_TimePeriod Object (
                            [internal_gapi_mappings:protected] => Array ( )
                            [closeDay] => Saturday
                            [closeTime] => 14:00:00
                            [openDay] => Saturday
                            [openTime] => 12:00:00
                            [modelData:protected] => Array ( )
                            [processed:protected] => Array ( )
                        )
                )
        )

How can I find out what is wrong?

1 Expert replyverified_user

Re: Error Request contains an invalid argument when using setRegularHours

Google Employee
# 2
Google Employee

Hi @Hans E,

 

The PHP variable you dumped for the Google_Service_Mybusiness_BusinessHours Object looks okay. There might be something else that’s wrong with your implementation.

 

Since the PHP client library doesn’t currently support the display of detailed error messages, you should follow the Make a simple HTTP request step-by-step guide on the Google Developers site to learn how to use the OAuth 2.0 Playground for troubleshooting errors with detailed error messages when sending requests with data via the Google My Business API.

 

Please follow the code snippet below to set regularHours with a break in business hours and specialHours for a location with the PHP client library:

$location = new Google_Service_Mybusiness_Location();

$businessHours = new Google_Service_Mybusiness_BusinessHours();

 $timePeriods = array();

 $days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

 foreach ($days as $day) {

   $timePeriod = new Google_Service_Mybusiness_TimePeriod();

   $timePeriod->setOpenDay($day);

   $timePeriod->setOpenTime("8:00");

   $timePeriod->setCloseTime("12:00");

   $timePeriod->setCloseDay($day);

   $timePeriods[] = $timePeriod;

   $timePeriod = new Google_Service_Mybusiness_TimePeriod();

   $timePeriod->setOpenDay($day);

   $timePeriod->setOpenTime("14:00");

   $timePeriod->setCloseTime("18:00");

   $timePeriod->setCloseDay($day);

   $timePeriods[] = $timePeriod;

 }

 $timePeriod = new Google_Service_Mybusiness_TimePeriod();

 $timePeriod->setOpenDay("Saturday");

 $timePeriod->setOpenTime("6:00");

 $timePeriod->setCloseTime("2:00");

 $timePeriod->setCloseDay("Sunday");

 $timePeriods[] = $timePeriod;

 $businessHours->setPeriods($timePeriods);

 

 $specialHours = new Google_Service_Mybusiness_SpecialHours();

 $specialHourPeriods = array();

 $specialHourPeriod = new Google_Service_Mybusiness_SpecialHourPeriod();

 $startDate = new Google_Service_Mybusiness_Date();

 $startDate->setMonth(7);

 $startDate->setDay(4);

 $startDate->setYear(2016);

 $specialHourPeriod->setStartDate($startDate);

 $specialHourPeriod->setOpenTime("6:00");

 $specialHourPeriod->setCloseTime("2:00");

 $endDate = new Google_Service_Mybusiness_Date();

 $endDate->setMonth(7);

 $endDate->setDay(5);

 $endDate->setYear(2016);

 $specialHourPeriod->setEndDate($endDate);

 $specialHourPeriods[] = $specialHourPeriod;

 $specialHours->setSpecialHourPeriods($specialHourPeriods);

 

 $location->setRegularHours($businessHours);

 $location->setSpecialHours($specialHours);

 

Thanks,

Terry

Marked as Best Answer.
Solution
Accepted by topic author Hans E
October 2016

Error Request contains an invalid argument when using setRegularHours

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
The reason for the error is the time format "14:00:00".
Google_Service_Mybusiness_TimePeriod->setOpenTime accepts the time format with seconds, but locations->create throws an error, when seconds are included!

Re: Error Request contains an invalid argument when using setRegularHours

Google Employee
# 4
Google Employee

Hi @Hans E,

 

According to the specifications of openTime and closeTime fields of the TimePeriod object, you are supposed to provide a time in 24hr ISO 8601 extended format (hh:mm). Valid values are 00:00-24:00, where 24:00 represents midnight at the end of the specified day field.

 

Thanks,

Terry