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

Patch Location error

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


I'm using the C# Client Library for Google My Business and I'm managing to return accounts and locations successfully.  But, when I use the Patch command it is giving me the following error:


Request contains an invalid argument. [400]
Errors [
Message[Request contains an invalid argument.] Location[ - ] Reason[badRequest] Domain[global]


The code I am using for the Patch command is this (I ultimately want to update opening hours so I am trying to update just one until I get it working):


Data.Location location = locationsResult.Locations[0];

foreach (Data.TimePeriod tp in location.RegularHours.Periods)
if (tp.OpenDate == "MONDAY")
tp.CloseTime = "17:45";

AccountsResource.LocationsResource.PatchRequest locationPatchRequest = service.Accounts.Locations.Patch(location, location.Name);
locationPatchRequest.LanguageCode = "en";
locationPatchRequest.ValidateOnly = false;
locationPatchRequest.FieldMask = "location.RegularHours.Periods";
Data.Location patchResult = locationPatchRequest.Execute();


... I have tried to follow the example in the reply here but I get an error because the code is not recognising 'UpdateLocationRequest' type.

1 Expert replyverified_user
Marked as Best Answer.
Accepted by topic author Shark S
July 2016

Re: Patch Location error

Google Employee
# 2
Google Employee

Hi @Shark S,


Judging from the source code you provided, your fieldMask was set incorrectly. The fieldMask of a PATCH request consists of a comma-separated list of fully qualified names of fields to update. In your case, when you are trying to update the opening hours for the specified location, the fieldMask should be “regularHours”. You also implemented the BusinessHours object incorrectly. The source code from the link you provided in your post is for v2 of the Google My Business API and is deprecated.


The following is a code snippet for updating the hours for the specified location with the C# client library:

// Creates and executes the request.

string name = location.Name;

location.Name = null;


// Business hours

IList<TimePeriod> periods = new List<TimePeriod>();

string[] days = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };


foreach (string day in days)


  TimePeriod period = new TimePeriod();

  period.OpenDay = day;

  period.OpenTime = "9:00";

  period.CloseTime = "17:00";

  period.CloseDay = day;



BusinessHours businessHours = new BusinessHours();

businessHours.Periods = periods;

location.RegularHours = businessHours;


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

locationUpdateRequest.LanguageCode = "en";

locationUpdateRequest.FieldMask = "regularHours";

locationUpdateRequest.ValidateOnly = false;

location = locationUpdateRequest.Execute();


I hope this helps solve your problem.




Re: Patch Location error

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Terry, thanks this has solved the problem. :)