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

Request contains an invalid argument. [400] error while create location

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

Hi,

 

When I am trying to create Location through C# library then I am getting (Request contains an invalid argument 400).

 

Error Detail.

Google.Apis.Requests.RequestError

Request contains an invalid argument. [400]

Errors [

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

]

 

Below is My code.

-------------------------------------------------------------------------------------------------------------------------------

Location locData = new Location();
Address addrDetails = new Address();

IList<string> aLines = new List<string>();
aLines.Add("Business Park");
aLines.Add("Other Road");

addrDetails.AddressLines = aLines;
addrDetails.Country = "US";
addrDetails.Locality = "Raymond";
addrDetails.PostalCode = "60914";

locData.Address = addrDetails;

locData.LocationName = "Test Co 99";
locData.WebsiteUrl = "http://www.test.com";
locData.StoreCode = "TEST999";
locData.PrimaryPhone = "(501) 268-3511";

Category catDetails = new Category();
catDetails.Name = "Hotel";

locData.PrimaryCategory = catDetails;

locData.Latlng = new LatLng();
locData.Latlng.Latitude = 54.099198;
locData.Latlng.Longitude = -0.933619;


Location newDetails = service.Accounts.Locations.Create(locData, account.Name).Execute();

 

-----------------------------------------------------------------------------------------------------------------------------

What is wrong in code.

 

Thanks

1 Expert replyverified_user

Re: Request contains an invalid argument. [400] error while create location

Google Employee
# 2
Google Employee

Hi @ICE P,

 

Judging from the source code you provided, I notice a couple of errors in your POST request for creating a new location. Your Location object missed the required categoryId field of the Category object for the primaryCategory field as well as the administrativeArea field of the Address object. The latitude and longitude in your LatLng object for the latlng field belong to a location in the UK while the country field value of the Address object is set to “US”. Please use a precise, accurate address to describe your business location.

 

The C# 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.

 

Thanks,

Terry

Re: Request contains an invalid argument. [400] error while create location

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
You're missing LanguageCode and RequestId.

var newDetailsRequest = service.Accounts.Locations.Create(locData, account.Name);
newDetailsRequest.LanguageCode="en";
newDetailsRequest.RequestId="UniqueId";

Location newDetails = newDetailsRequest.Execute();