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
3.1K members online now
3.1K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

GMB API v3 Error on Name Format

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

Hello,

 

Trying to use the Patch to update a location's information and receive this error response:

 
java.lang.IllegalArgumentException: Parameter name must conform to the pattern ^accounts/[^/]*/locations/[^/]*$

 

 

I believe we have information correctly formatted in this example request: 

 
{additionalPhones=[9199626551], address={addressLines=[310 PITTSBORO ST,null], administrativeArea=NC, country=US, locality=CHAPEL HILL, postalCode=27516}, locationName=State Employees' Credit Union, name=accounts/114515985899098925999/locations/17043764712644355368, openInfo={status=OPEN}, primaryPhone=9199626551, regularHours={periods=[{closeDay=Monday, closeTime=17:00, openDay=Monday, openTime=9:00}, {closeDay=Tuesday, closeTime=17:00, openDay=Tuesday, openTime=9:00}, {closeDay=Wednesday, closeTime=17:00, openDay=Wednesday, openTime=9:00}, {closeDay=Thursday, closeTime=17:00, openDay=Thursday, openTime=9:00}, {closeDay=Friday, closeTime=17:00, openDay=Friday, openTime=9:00}]}, storeCode=1}
 
Any help on this is appreciated to resolve the error!
 

 

 

1 Expert replyverified_user

Re: GMB API v3 Error on Name Format

[ Edited ]
Google Employee
# 2
Google Employee

Hi @Amanda S,

 

I notice a couple of errors in the JSON request body of the PATCH request you provided. The format of the JSON request body is incorrect; You included the name field of a Location object that’s read-only and should be omitted in your PATCH request; You didn’t provide the categoryId field of a Category object that must be specified for modifying a category when creating or updating a location.

 

I suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site to learn how to use the OAuth 2.0 Playground for troubleshooting errors with detailed error messages when sending requests with data via the Google My Business API.

 

It’s best practice to always use a fieldMask for specific fields when you are updating a location via the API so that your other location data are preserved.

 

The following is a sample PATCH request with your given location information for updating the specified location (you need to provide your custom fieldMask):

https://mybusiness.googleapis.com/v3/accounts/114515985899098925999/locations/17043764712644355368?languageCode=en&fieldMask=field1,field2&validateOnly=false

{
 "storeCode": "1",
 "additionalPhones": [
   "(919) 962-6551"
 ],
 "regularHours": {
   "periods": [
     {
       "openDay": "MONDAY",
       "closeDay": "MONDAY",
       "openTime": "09:00",
       "closeTime": "17:00"
     },
     {
       "openDay": "TUESDAY",
       "closeDay": "TUESDAY",
       "openTime": "09:00",
       "closeTime": "17:00"
     },
     {
       "openDay": "WEDNESDAY",
       "closeDay": "WEDNESDAY",
       "openTime": "09:00",
       "closeTime": "17:00"
     },
     {
       "openDay": "THURSDAY",
       "closeDay": "THURSDAY",
       "openTime": "09:00",
       "closeTime": "17:00"
     },
     {
       "openDay": "FRIDAY",
       "closeDay": "FRIDAY",
       "openTime": "09:00",
       "closeTime": "17:00"
     }
   ]
 },
 "locationName": "State Employees' Credit Union",
 "primaryPhone": "(919) 962-6551",
 "address": {
   "postalCode": "27516",
   "country": "US",
   "administrativeArea": "NC",
   "addressLines": [
     "310 Pittsboro St"
   ],
   "locality": "Chapel Hill"
 },
 "openInfo": {
   "status": "OPEN"
 },
 "primaryCategory": {
   "name": "Credit Union",
   "categoryId": "gcid:credit_union"
 },
}

 

The following is a code snippet for updating the specified location with the Java client library:

   // Street address

   List<String> addressLines = new ArrayList<>();

   addressLines.add("310 Pittsboro St");

   Address address =

       new Address()

           .setAddressLines(addressLines)

           .setLocality("Chapel Hill")

           .setAdministrativeArea("NC")

           .setCountry("US")

           .setPostalCode("27516");

 

   // Additional Phones

   List<String> additionalPhones = new ArrayList<>();

   additionalPhones.add("(919) 962-6551");

 

   // Business hours

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

   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);

 

   // OpenInfo

   OpenInfo openInfo = new OpenInfo();

   openInfo.setStatus("OPEN");

 

   String locationResourceName = location.getName();

   location

       .setName(null)

       .setAddress(address)

       .setRegularHours(businessHours)

       .setLocationName("State Employees' Credit Union")

       .setStoreCode("1")

       .setPrimaryPhone("(919) 962-6551")

       .setAdditionalPhones(additionalPhones)

       .setPrimaryCategory(

           new Category().setName("Credit Union").setCategoryId("gcid:credit_union"))

       .setOpenInfo(openInfo);

 

   Mybusiness.Accounts.Locations.Patch updateLocation =

       mybusiness.accounts().locations().patch(locationResourceName, location);

   updateLocation

       .setLanguageCode("en")

       //.setFieldMask("locationName,regularHours,primaryCategory,openInfo")

       .setValidateOnly(false)

       // If you get a request validation error you can inject the following header into any call as

       // shown below to get a more descriptive error and then it will throw trying to digest that

       // richer message.

       // This is a bug in the client library generator that will be fixed in the future.

       .getRequestHeaders()

       .set("X-GOOG-API-FORMAT-VERSION", 2);

   Location updatedLocation = updateLocation.execute();

 

Thanks,

Terry