AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

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

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I created a test location through API and it went just fine. But when I tried to make a PATCH request, I see the following error.

 

Error:

{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}

URL:

https://mybusiness.googleapis.com/v3/accounts/100305805954398005065/locations/16471077826733155804?l...

 

Payload:

{"additionalCategories":[{"categoryId":"gcid:investment_bank"},{"categoryId":"gcid:investment_service"},{"categoryId":"gcid:boot_store"},{"categoryId":"gcid:bank"}],"address":{"addressLines":["1154 S Clark"],"administrativeArea":"Illinois","country":"US","locality":"Chicago","postalCode":"60605"},"locationName":"SIM test Version V3","openInfo":{"status":"Open"},"primaryCategory":{"categoryId":"gcid:shoe_store"},"primaryPhone":"(312) 340-9332","regularHours":{"periods":[{"closeDay":"Sunday","closeTime":"08:30","openDay":"Sunday","openTime":"10:30"},{"closeDay":"Monday","closeTime":"08:30","openDay":"Monday","openTime":"11:00"},{"closeDay":"Tuesday","closeTime":"08:30","openDay":"Tuesday","openTime":"15:30"},{"closeDay":"Wednesday","closeTime":"13:00","openDay":"Wednesday","openTime":"15:30"}]},"storeCode":"attributesTest","websiteUrl":"http://9gag.com/"}

 

I tried with names in the category entity along with id too. Nothing changed. The error doesn't really specify any details on what argument is invalid.

 

Thanks for the help.

 

2 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Krishna P
December 2016

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

I am using the straight json to post. I think the problem is for the field mask, I was using the same format I used for v2 and for v3 I believe its simple camel case and no need to include the parent entity. For example, locationName instead of location.locationName. 

View solution in original post

Problem with PATCH request V 3.0

Follower ✭ ✭ ☆
# 2
Follower ✭ ✭ ☆

Question:  Are you using one of the helper libraries, or is this a straight json post?

 

Also I notice your open time is after you close time.  

Marked as Best Answer.
Solution
Accepted by topic author Krishna P
December 2016

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

I am using the straight json to post. I think the problem is for the field mask, I was using the same format I used for v2 and for v3 I believe its simple camel case and no need to include the parent entity. For example, locationName instead of location.locationName. 

Problem with PATCH request V 3.0

Follower ✭ ✭ ☆
# 4
Follower ✭ ✭ ☆

you are correct in the change in using parent entity in the field mask

 

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

@Jeremy M

you seem to have a good understanding of working with the GMB API.

i have posted  some PHP code and was wondering if you could take a look at it and let me know what I am doing wrong on the patch

https://www.en.advertisercommunity.com/t5/Basics-for-Business-Owners/Patch-issue-with-location-objec...

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

I observed 2 things from what code you provided. I don't think there is any problem with how you are assigning the values to the object or even sending a PATCH request. t 

 

1. I would try to build you own json object and make a request. The reason why I suggest this is because the SDK for PHP might not be complete enough to surface the complete error message. The same thing happened to me. I used .NET SDK and it literally didn't provide any extra error details. The bject your build using SDK and raw JSON are different but it might give you some insight on the error.

 

2. Are you passing the "test" for addresslines and cities ? Google is very strict to match address and check its validity. I suggest you pass the actual values for testing. 

 

For example, using .NET SDK, I would get a 400 error with argument invalid always and I serialized my object and made a call through Http and I still got 400 error but with more details. This helped me fix my problems.

 

Hope this helps.

 

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

@Krishna p

Thank you that helped huge amounts.

 

I do have another question. I did as you mentioned and used the actual address for the location that I was working on and that worked mostly.

If I have validateOnly set to false everything works and the address becomes the current live address.

BUT if I change it to true the script runs but no updates are made (and that I expected) BUT it does not put it in the GMB URI as a location with a pending update. Is the true for that value just for us to test the script and if it runs then it is good and can change the validateOnly to false?

 

 

 

 

 

 

$name = 'removed for this post';

$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);
    try { $updatedlocation = $mybusinessService->accounts_locations->patch($name, $location, array( "languageCode"=>"en",'validateOnly' => false,"fieldMask"=>"address" ));
    echo "done";
     } catch (Exception $e) {
      print "Caught exception: " . $e->getMessage() . "\n"; }

Re: Problem with PATCH request V 3.0

[ Edited ]
Google Employee
# 8
Google Employee

Hi @Krishna P,

 

You are correct, as per the Change Log for the v3 of Google My Business API, Field masks of location object should no longer include the location. prefix for included fields.

 

Thanks,

The Google My Business API team

Problem with PATCH request V 3.0

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Ryan,

 

Yes. That is exactly the purpose of it, just to validate.

Re: Problem with PATCH request V 3.0

Google Employee
# 10
Google Employee

Hi @Ryan P,

 

If you set the validateOnly boolean field to true when sending a PATCH request to update a specified location via the Google My Business API, the request is validated without actually updating the location.

 

Thanks,

Shalini