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

Updating an Existing Store Code Using GMB API

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

Hello.  Is it possible to update/change existing Store Codes in bulk using the GMB API? If a location has already been created in GMB and now needs the Store Code to be changed is this something the API has a capability for? I was thinking no since it is a primary source of linking our location data to GMB, but looking for confirmation.

2 Expert replyverified_user

Re: Updating an Existing Store Code Using GMB API

Google Employee
# 2
Google Employee

Hi @Amanda S,

 

Yes, you can add a new or update an existing location with the storeCode field of the Location object at any time via the Google My Business API since the storeCode is simply a unique external identifier for a location inside a given account for the means of associating the location with your own records. On the other hand, the name field of the Location object is the Google identifier for this location and is ready-only and immutable.

 

For more specifications about the store code field, please check out this section of an article in the Google My Business Help Center.

 

Thanks,

Terry

Re: Updating an Existing Store Code Using GMB API

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Terry,

Thank you for the information. Just to make sure I have this correct...

Say we have a verified location:
storeCode: ABC1
locationName: ABC, Inc.
address: 123 Main St, Baltimore, MD 21212
primaryPhone: 410-555-1234

And we want to update just the Store Code, we can submit the following and the API will "know" we are not creating a new location, but instead updating the existing record with the new Store Code?
storeCode: 9876
locationName: ABC, Inc.
address: 123 Main St, Baltimore, MD 21212
primaryPhone: 410-555-1234

I appreciate the assistance and expertise here. I am more familiar in the bulk upload process online in GMB, and I am just wanting to prevent any issues as we transition to the API. I know if we tried this same scenario in the bulk upload GMB would mark the change as a new location. Any additional insights or references are greatly appreciated.

Thanks,
Amanda

Re: Updating an Existing Store Code Using GMB API

Google Employee
# 4
Google Employee

Hi @Amanda S,

 

When you send a PATCH request with the locationId to update the storeCode field of the Location object for the specified location in Google My Business, you will not create a new duplicate location in the UI if you provide a different value for the storeCode field. The POST request to create a new location under the specified account is separate from the PATCH request, so there’s no way you will create a new location by sending the PATCH request to update the existing location. This is analogous to updating the store code of a location through the Google My Business UI. However, when you import your bulk upload spreadsheet to update multiple locations, you should use the same store codes and location information as you have in the past so that the system doesn’t create duplicate locations.

 

Please note that 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.

 

Thanks,

Terry

Re: Updating an Existing Store Code Using GMB API

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi @Terry W,

 

Thank you for the information. We were able to get this working, but with one additional issue. It appears when we are receiving locations on the batchGet calls it is only for 100 records per account. We are a bulk verified account and have several business accounts with more than 100 locations. Is there a way to increase the number of results returned beyond 100 on the batchGet?

 

Thanks,

Amanda

Re: Updating an Existing Store Code Using GMB API

Google Employee
# 6
Google Employee

Hi @Amanda S,

 

Please check out my post about how to send a GET request to listing all paginated locations for the specified account.

 

Thanks,

Terry

Updating an Existing Store Code Using GMB API

[ Edited ]
Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hi @Terry W,

 

We are still having some issues regarding updating the storeCode field. We do not want to update the phone, category, photo or label fields, but all others are to be updated with the patch. Here is what we are sending. Possibly issue with with the fieldMask? Any feedback is appreciated.

 

 

Mybusiness.Accounts.Locations.Patch updateLocation = mybusiness.accounts().locations().patch(name, location);
 
updateLocation.setLanguageCode("en").setFieldMask("primaryPhone").setFieldMask("primaryCategory").setFieldMask("photos").setFieldMask("labels").setValidateOnly(false);
 
{additionalPhones=[2155551234], address={addressLines=[1234 Moreland Rd], administrativeArea=MD, country=US, locality=Baltimore, postalCode=21212}, locationName=My Business, openInfo={status=OPEN}, primaryCategory={categoryId=gcid:credit_union, name=Credit}, primaryPhone=2155550077, regularHours={periods=[{closeDay=Monday, closeTime=17:00, openDay=Monday, openTime=08:00}, {closeDay=Tuesday, closeTime=17:00, openDay=Tuesday, openTime=08:00}, {closeDay=Wednesday, closeTime=17:00, openDay=Wednesday, openTime=08:00}, {closeDay=Thursday, closeTime=17:00, openDay=Thursday, openTime=08:00}, {closeDay=Friday, closeTime=17:00, openDay=Friday, openTime=08:00}]}, storeCode=ABC-062}

 

 

The location currently has storeCode "062" in GMB and we are trying to update this to "ABC-062" along with other location information including hours. Additional information here as well.

 

Patch request is: 
{additionalPhones=[(919) 962-6551], address={addressLines=[310 Pittsboro St], administrativeArea=NC, country=US, locality=Chapel Hill, postalCode=27516}, locationName=State Employees' Credit Union, openInfo={status=OPEN}, primaryCategory={categoryId=gcid:credit_union, name=Credit}, primaryPhone=(919) 962-6551, regularHours={periods=[{closeDay=Monday, closeTime=17:00, openDay=Monday, openTime=08:00}, {closeDay=Tuesday, closeTime=17:00, openDay=Tuesday, openTime=08:00}, {closeDay=Wednesday, closeTime=17:00, openDay=Wednesday, openTime=08:00}, {closeDay=Thursday, closeTime=17:00, openDay=Thursday, openTime=08:00}, {closeDay=Friday, closeTime=17:00, openDay=Friday, openTime=08:00}]}, storeCode=101}

Locations after update: 

{"adWordsLocationExtensions":{},"additionalPhones":["(919) 962-6551"],"address":{"addressLines":["310 Pittsboro St"],"administrativeArea":"NC","country":"US","locality":"Chapel Hill","postalCode":"27516"},"latlng":{"latitude":42.713794,"longitude":-71.163598},"locationKey":{"placeId":"ChIJ8Xy4hgwH44kRNaiTjTNLz6w","plusPageId":"103905730459697727805"},"locationName":"State Employees' Credit Union","locationState":{"canDelete":true,"canUpdate":true,"isSuspended":true,"isDisconnected":true},"metadata":{"mapsUrl":"https://maps.google.com/maps?cid=12452254179493390389"},"name":"accounts/114515985899098925999/locations/16805323811872814884","openInfo":{"status":"OPEN"},"primaryCategory":{"categoryId":"gcid:credit_union","name":"Credit Union"},"primaryPhone":"(919) 962-6551","regularHours":{"periods":[{"closeDay":"MONDAY","closeTime":"17:00","openDay":"MONDAY","openTime":"09:00"},{"closeDay":"TUESDAY","closeTime":"17:00","openDay":"TUESDAY","openTime":"09:00"},{"closeDay":"WEDNESDAY","closeTime":"17:00","openDay":"WEDNESDAY","openTime":"09:00"},{"closeDay":"THURSDAY","closeTime":"17:00","openDay":"THURSDAY","openTime":"09:00"},{"closeDay":"FRIDAY","closeTime":"17:00","openDay":"FRIDAY","openTime":"09:00"}]},"storeCode":"1","languageCode":"en"}


java code:

		Location location = new Location();

		// Street address
		List<String> addressLines = new ArrayList<String>();
		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<String>();
		additionalPhones.add("(919) 962-6551");

		// 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("08: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("101").setPrimaryPhone("(919) 962-6551")
				.setAdditionalPhones(additionalPhones)
				.setPrimaryCategory(new Category().setName("Credit").setCategoryId("gcid:credit_union"))
				.setOpenInfo(openInfo);
		
		
		System.out.println("Patch request is: "+ location);

		Mybusiness.Accounts.Locations.Patch updateLocation = mybusiness.accounts().locations()
				.patch("accounts/114515985899098925999/locations/16805323811872814884", location);
		updateLocation.setLanguageCode("en").setFieldMask("primaryCategory").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();
		System.out.println("Locations after update: " + updatedLocation);

 

Thanks,

Amanda S.

Re: Updating an Existing Store Code Using GMB API

Google Employee
# 8
Google Employee

Hi @Amanda S,

 

Judging from the source code you provided, the fieldMask for your PATCH request to update the specified location was set incorrectly. The fieldMask specifies the specific fields to update, and not oppositely the specific fields you want to preserve. You set the fieldMask multiple times in your provided source code and only the last fieldMask you set would be effective.

 

If you only want to update the storeCode field of the specified location, you can use the following code snippet to set the fieldMask for your application using the Java client library:

   updateLocation

       .setLanguageCode("en")

       .setFieldMask("storeCode")

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

 

If you want to update all fields of the specified location except for the primaryPhone, additionalPhones, primaryCategory, additionalCategories, photos and labels fields, you can use the following code snippet to set the fieldMask for your application using the Java client library:

   updateLocation

       .setLanguageCode("en")

       .setFieldMask("storeCode,locationName,address,websiteUrl,regularHours,specialHours,serviceArea,adWordsLocationExtensions,openInfo,attributes"

           )    

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

 

I hope this helps. Please note that it's best practice to always include a fieldMask for specific fields when you are updating a location to avoid overwriting data inadvertently.

 

Thanks,

Terry

Updating an Existing Store Code Using GMB API

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Hi,

 

I am having problem in updating addressLines using google my business api.

 

1) Field Mask:

websiteUrl,primaryPhone,locationName,address

 

Response:

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

 

2) Field Mask: websiteUrl,primaryPhone,locationName,address.country,address.locality,address.

administrativeArea,address.postalCode,address.addressLines

 

Response: 

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

 

3) 

Field Mask:

websiteUrl,primaryPhone,locationName,address.country,address.locality,address.

administrativeArea,address.postalCode

 

It takes this field mask as a valid input. The rest of code is kept same for all the 3 above scenarios. In the last one, I just removed addressLines from the field mask. I am using php my business apis. 

 

Does google mybusiness apis doesn't allow to update addressLines ?

 

Looking forward to your reply.

 

 

 

Re: Updating an Existing Store Code Using GMB API

Google Employee
# 10
Google Employee

Hi @Rahul A,

 

1) Please provide us with the the specific locationId for the location and the full HTTP request message of the PATCH request including the URI, query parameters, and the JSON payloads of request body as well as the response body for triggering this error so that we can help you troubleshoot this issue further.

 

2) & 3)  As you mentioned in your post, since you are trying to update the country for your location, please note, according to the Google My Business API document, once a location is created, the country cannot be changed. So we recommended you do not change the country when patching a location via the Google My Business API.

 

I hope this helps!

 

Thanks,

Shalini, Google My Business API team