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

400 INVALID_ARGUMENT when creating new Locations

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

Hi,

I'm using a service account to create locations using the Java client library. The issue is that the API always responds with a 400 error. I can't figure out what the problem is.

Here's the code that's almost completely identical to the example provided in the documentation. The only difference is that Mybusiness became MyBusiness (obsolete documentation?):

        // Street address
        List addressLines = new ArrayList();
        addressLines.add("Level 5, 48 Pirrama Road");
        Address address = new Address()
                .setAddressLines(addressLines)
                .setLocality("Pyrmont")
                .setAdministrativeArea("NSW")
                .setCountry("AU")
                .setPostalCode("2009");

        // Business hours
        List<TimePeriod> periods = new ArrayList<TimePeriod>();
        List<String> days = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");

        for (String day : days) {
            TimePeriod period = new TimePeriod()
                    .setOpenDay(day)
                    .setOpenTime("9:00")
                    .setCloseTime("17:00")
                    .setCloseDay(day);
            periods.add(period);
        }
        BusinessHours businessHours = new BusinessHours()
                .setPeriods(periods);
        Location location = new Location()
                .setAddress(address)
                .setRegularHours(businessHours)
                .setLocationName("Google Sydney")
                .setStoreCode("GOOG-SYD")
                .setPrimaryPhone("02 9374 4000")
                .setPrimaryCategory(new Category().setName("Software Company"))
                .setWebsiteUrl("https://www.google.com.au/");

        MyBusiness.Accounts.Locations.Create createLocation =
                mybusiness.accounts().locations().create(accountName, location);
        createLocation.setRequestId("1a84939c-ab7d-4581-8930-ee35af6fefac");
        createLocation.setLanguageCode("en-AU");

        Location createdLocation = createLocation.execute();

Another unsuccessful attempt:

        List addressLines = new ArrayList();
        addressLines.add("1599 Amphitheatre Parkway");
        Address address = new Address()
                .setAddressLines(addressLines)
                .setLocality("Mountain View")
                .setAdministrativeArea("CA")
                .setCountry("US")
                .setPostalCode("94043");

        Location location = new Location()
                .setAddress(address)
                .setLocationName("TestLocation123")
                .setStoreCode("TestStoreCode123")
                .setPrimaryPhone("123123123")
                .setPrimaryCategory(new Category().setName("Bank"))
                .setWebsiteUrl("http://google.com/");

        MyBusiness.Accounts.Locations.Create createLocation = mybusiness.accounts().locations().create(accountName, location);
        createLocation.setValidateOnly(true);
        createLocation.setLanguageCode("en-US");

        Location createdLocation = createLocation.execute();

The error message:

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Request contains an invalid argument.",
    "reason" : "badRequest"
  } ],
  "message" : "Request contains an invalid argument.",
  "status" : "INVALID_ARGUMENT"
}

Other requests, such as retrieving the list of all associated locations, work fine and do not return this error message. The project is whitelisted for My Business API usage and the service account is impersonating an account that has given its user consent.

Used java library: google-api-services-mybusiness-v3p2-java-rev20170110.jar

Maven dependencies:

    <dependencies>
        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.22.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.22.0</version>
        </dependency>
    </dependencies>

Am I doing something wrong?

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Oleg G
February 2017

Re: 400 INVALID_ARGUMENT when creating new Locations

[ Edited ]
Google Employee
# 2
Google Employee

Hi @Oleg G,

 

Judging from the source code you provided, I notice that you are missing couple of parameters in your code when creating a new location. You didn’t add validateOnly and requestId in your code. We suggest you please follow the code below to see if it fixes the issue:

 

 Mybusiness.Accounts.Locations.Create createLocation =
 mybusiness.accounts().locations().create(account.getName(), location);
 createLocation.setValidateOnly(false);
 createLocation.setLanguageCode("en-US");
 createLocation.setRequestId(UUID.randomUUID().toString());
 Location createdLocation = createLocation.execute();

 

Since you are using Java client library, please add this additional header to your requests to enable more detailed error messages in responses:

X-GOOG-API-FORMAT-VERSION: 2

 

Thanks,

Shalini

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Oleg G
February 2017

Re: 400 INVALID_ARGUMENT when creating new Locations

[ Edited ]
Google Employee
# 2
Google Employee

Hi @Oleg G,

 

Judging from the source code you provided, I notice that you are missing couple of parameters in your code when creating a new location. You didn’t add validateOnly and requestId in your code. We suggest you please follow the code below to see if it fixes the issue:

 

 Mybusiness.Accounts.Locations.Create createLocation =
 mybusiness.accounts().locations().create(account.getName(), location);
 createLocation.setValidateOnly(false);
 createLocation.setLanguageCode("en-US");
 createLocation.setRequestId(UUID.randomUUID().toString());
 Location createdLocation = createLocation.execute();

 

Since you are using Java client library, please add this additional header to your requests to enable more detailed error messages in responses:

X-GOOG-API-FORMAT-VERSION: 2

 

Thanks,

Shalini

400 INVALID_ARGUMENT when creating new Locations

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi,

 

Adding the header revealed that the Category required an ID. Adding that value resulted in a successful request. You might want to update the example in the documentation.

 

Thank you for the help.