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

Update location via MyBusiness API (v3)

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

Hi i'm trying to update website for  location via MyBusiness API (v3) using OAuth 2.0 flow + google-api-php-client +Mybusiness PHP Classes. 

 

 

$client = new Google_Client();
$client->setClientId($client_id);
//...


$sLocationName = "MyLocationName";
$sName = "accounts/110588984792951515795/locations/13808205929060313087";

updateLocation($sLocationName,$sName,$client);

function updateLocation($sLocationName,$sName,$client)
{
$aLocationInfo = array();
$aLocationInfo['ValidateOnly'] = false;
$aLocationInfo['languageCode'] = "de-DE";
$aLocationInfo['StoreCode'] = "XXX-000111";


$location = new Google_Service_Mybusiness_Location();
$location->setName($sName);
$location->setLocationName($sLocationName);
$location->setWebsiteUrl("http://www.mywebsite.com");
try
{
$mybusinessService = new Google_Service_Mybusiness($client);
$updatelocation = $mybusinessService->accounts_locations->patch($sName,$location,array( "languageCode"=>$aLocationInfo['languageCode'],'validateOnly' => $aLocationInfo['ValidateOnly'],"fieldMask"=>"websiteUrl"));

}
catch(Exception $e)
{
print "Caught exception: " . $e->getMessage() . "\n";

}

return $updatelocation;
}

 Error looks like this:

Error calling PATCH https://mybusiness.googleapis.com/v3/accounts/110588984792951515795/locations/13808205929060313087?languageCode=de-DE&validateOnly=false: (400) Request contains an invalid argument

Can someone help me?

 

I want also  to update the description for a location is this possible in v3?

 

Thank you in advance.

 

Best regards

Iliyan Hristov

 

 

 

 

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Iliyan H
May 2016

Re: Update location via MyBusiness API (v3)

[ Edited ]
Google Employee
# 2
Google Employee

Hi @Iliyan H,

 

Judging from the source code you provided, you included the name field of a Location object in your PATCH request for updating a location in the following LOC:

$location->setName($sName);

 

You should omit the read-only name field of a Location object when creating or updating a location. Please make sure you take out the name field in your PATCH request for updating the specified location to avoid the 400 Bad Request error.

 

The PHP client library doesn’t currently support the display of detailed error messages. Please follow the Make a simple HTTP request step on the Get Started page of the documentation website to learn how to use the OAuth 2.0 Playground for troubleshooting errors when sending requests with data via the Google My Business API.

 

The description field is not currently supported through v3 of the Google My Business API. Please use best practice that is to always include a fieldMask for specific fields when you are updating a location to avoid overwriting data inadvertently.

 

Thanks,

Terry

Re: Update location via MyBusiness API (v3)

[ Edited ]
Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆

Hi Terry,

thank you it's working. I just removed the "$location->setName($sName);"

Where can I see all fields that not supported?

Have a nice day!

Best regards
Iliyan Hristov

Re: Update location via MyBusiness API (v3)

Google Employee
# 4
Google Employee

Hi @Iliyan H,

 

You can make a side-by-side comparison between the fields of the Location object and the location fields in the UI listed on this page. Please note that there are more available fields of the Location object than the available location fields in the UI and the Description field is currently the only field in the UI not supported via the Google My Business API.

 

Thanks,

Terry

Re: Update location via MyBusiness API (v3)

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Hello,

Is there a list with valid fieldMasks? It would help get rid of some `Request contains an invalid argument` errors.

Thanks,
Peter

Re: Update location via MyBusiness API (v3)

Google Employee
# 6
Google Employee

Hi @Peter P,

 

There’s not such a list for valid fields to include in the fieldMask. All fields of the Location object except for the name field and any field marked as @OutputOnly can be included in the fieldMask of a PATCH request to indicate the specific fields to update. Please note that the name field of the Location object is read-only and should be omitted in all requests.

 

Thanks,

Terry