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

Location Address PATCH

[ Edited ]
Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hello all. I'm working on some patch function and I got stuck to update the address from some location. I tried to pass the "address" on "fieldMask" but I saw that is no longer working in V3. How could I update the address from some location?

 

My code:

$name = $locationsList[0]['name'];

$location = new Google_Service_Mybusiness_Location();

 // $newAddress = new Google_Service_Mybusiness_Address();
 // $newAddress->setAddressLines("130 East Grand Ave, Suite E");
  // $newAddress->setLocality("El Segundo");
   // $newAddress->setAdministrativeArea("CA");
   // $newAddress->setCountry("US");
   // $newAddress->setPostalCode("90245");
    // $location->setAddress($newAddress);
 $location->setWebsiteUrl("http://www.mywebsite.com");
$location->setPrimaryPhone("02 9374 5000");

 $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("18:00");
   $timePeriod->setCloseDay($day);
   $timePeriods[] = $timePeriod;
 }
 $businessHours->setPeriods($timePeriods);
 $location->setRegularHours($businessHours);

$openInfo = new Google_Service_Mybusiness_OpenInfo();
// $openInfo->status = "CLOSED_PERMANENTLY";
$openInfo->status = "OPEN";
$location->setOpenInfo($openInfo);

$primaryCategory = new Google_Service_Mybusiness_Category();
$primaryCategory->setName("Adega");
$primaryCategory->setCategoryId("gcid:wine_store");
$location->setPrimaryCategory($primaryCategory);

$newAddress = new Google_Service_Mybusiness_Address();
$newAddress->setAddressLines("130 East Grand Ave, Suite E");
$newAddress->setLocality("El Segundo");
$newAddress->setAdministrativeArea("CA");
$newAddress->setCountry("US");
$newAddress->setPostalCode("90245");
$location->setAddress($newAddress);

try { $updatedlocation = $mybusinessService->accounts_locations->patch($name, $location, array( "languageCode"=>"pt-BR",'validateOnly' => false,"fieldMask"=>"websiteUrl,regularHours,openInfo,primaryCategory,primaryPhone" ));
echo "done";
 } catch (Exception $e) {
  print "Caught exception: " . $e->getMessage() . "\n";
}
1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Marcos L
March 2017

Re: Location Address PATCH

Google Employee
# 2
Google Employee

Hi @Marcos L,

 

After looking at the code you provided, I notice that you are missing the address field in comma-separated list of names of fields for the fieldMask parameter in your PATCH request while updating your location via the Google My Business API. Since you are trying to update the address, I suggest you please add address field in your patch request to see if it fixes your issue.

 

$mybusinessService->accounts_locations->patch($name, $location, array( "languageCode"=>"pt-BR",'validateOnly' => false," fieldMask"=>"websiteUrl,regularHours,openInfo,primaryCategory,primaryPhone,address"));

 

Please note, the PHP client library doesn’t currently support the display of detailed error messages, so I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.

 

Thanks,

Shalini

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Marcos L
March 2017

Re: Location Address PATCH

Google Employee
# 2
Google Employee

Hi @Marcos L,

 

After looking at the code you provided, I notice that you are missing the address field in comma-separated list of names of fields for the fieldMask parameter in your PATCH request while updating your location via the Google My Business API. Since you are trying to update the address, I suggest you please add address field in your patch request to see if it fixes your issue.

 

$mybusinessService->accounts_locations->patch($name, $location, array( "languageCode"=>"pt-BR",'validateOnly' => false," fieldMask"=>"websiteUrl,regularHours,openInfo,primaryCategory,primaryPhone,address"));

 

Please note, the PHP client library doesn’t currently support the display of detailed error messages, so I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.

 

Thanks,

Shalini

Location Address PATCH

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆

Thanks @Shalini S! I tried with the "address" parameter but I was changing the country, but I found that this could not be changed. 

Re: Location Address PATCH

Google Employee
# 4
Google Employee

Hi @Marcos L,

 

Please note, according to the Google My Business API document, once a location is created, the country cannot be changed.

 

Please let us know if you have any other questions about Google My Business API.

 

Thanks,

Shalini