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

Unable to Patch PhotoURL in Location Google My Business API

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

 We are trying to delete Cover Photo URL or Any Photo URL from Photo OR delete a Additional Category   in location to my business account even location is published using c#  but get the following error

 
Request contains an invalid argument. [400]
Errors [
Message[Request contains an invalid argument.] Location[ - ] Reason[badRequest] Domain[global]
]
Please review below image for Photo URL Issue.
 
photo1.jpgphoto2.jpg
Please review below image for Category Issue.
 
category.jpg
We are also passing the Mandatory Values like address, primary category, business hours.
 
Please help us ASAP.
1 Expert replyverified_user

Re: Unable to Patch PhotoURL in Location Google My Business API

Google Employee
# 2
Google Employee

Hi @Scout50 D,

 

I think you should clean up your code and use better mnemonic variable names because you are using createLocationRequest for a PATCH request, Responselist for a Location object, etc. Your item variable from a foreach loop will always be the last element in the list.

 

To remove a certain field from a Location object, you can simply assign the null value to that particular field. Note that you should remove the read-only name field from a Location object retrieved from a GET request when using it in a PATCH request, or else you will get a ValidationError. It's best practice to always use a fieldMask for updating specific fields so that your other location data are preserved.

 

Please follow the code snippet below for patching or removing the coverPhotoUrl and additionalCategories with the C# client library:

           // Gets all accounts for the authenticated user.

           var accountsListRequest = service.Accounts.List();

           ListAccountsResponse accountsResult = accountsListRequest.Execute();

 

           // For testing purposes, selects the very first account in the accounts array.

           Account account = accountsResult.Accounts[0];

 

           // Lists all locations for the specified account.

           var locationsListRequest = service.Accounts.Locations.List(account.Name);

           ListLocationsResponse locationsResult = locationsListRequest.Execute();

 

           // For testing purposes, selects the very first location in the locations array.

           Location location = locationsResult.Locations[0];

 

           // Updates one or more fields for the specified location.

           string name = location.Name;

           location.Name = null;

 

           location.Photos.CoverPhotoUrl = null;

           location.AdditionalCategories = null;

 

           var locationUpdateRequest = service.Accounts.Locations.Patch(location, name);

           locationUpdateRequest.LanguageCode = "en";

           locationUpdateRequest.FieldMask = "photos.coverPhotoUrl,additionalCategories";

           locationUpdateRequest.ValidateOnly = false;

           location = locationUpdateRequest.Execute();

 

In addition, you should learn to Make a simple HTTP request via OAuth 2.0 Playground for verifying your results since the C# client library doesn’t currently support the display of detailed error messages.

 

Thanks,

Terry