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

Java: Unable to update notifications for mybusiness account

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



I am  unable to update notifications for my business account with the created topic, Could someone please help me with this.

Below are the steps I have followed:

1) I have created a topic "my-business-updates" in my project. 

2) downloaded the jar "google-api-services-mybusiness-v3p1-java-rev20160926.jar"

3) OAuth process as follows


private static Credential buildCredential(String token, String secret)
        throws IOException, GeneralSecurityException {
        InputStream secrets = GoogleRtuSubscriptionUtil.class.getResourceAsStream("/gmb/client_secrets.json");
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(),
            new InputStreamReader(secrets));
        Credential credential = new GoogleCredential.Builder()
            .setRefreshListeners(Lists.newArrayList(new CredentialRefreshListnerImpl())).build();
        return credential;

4) created my business object as follows



Mybusiness mybusiness = new Mybusiness.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();

5) Now I am trying to update the notifications of account as follows:

// topicName as 'my-business-updates' 
Notifications notifications = new Notifications().setTopicName(topicName);
// accountName is of format 'accounts/1xxxxxxxx9/notifications'
            Mybusiness.Accounts.UpdateNotifications updateNotification = mybusiness.accounts()
                .updateNotifications(accountName, notifications);

 6) Below is the error that I received


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

Could someone please let me know what is the mistake I'm doing, I have spent almost 8hours on this but no clue? 



Note: I was able to update the account name using same mybusiness object as follows

private static void updateAccount(String accountName, String newAccountName) throws IOException {
        System.out.println("account name: " + accountName + " new account name: " + newAccountName);
        Account updateAccount = new Account();
        updateAccount.set("accountName", newAccountName);

        Mybusiness.Accounts.Update accountUpdate = mybusiness.accounts().update(accountName, updateAccount);
        Account updatedAccount = accountUpdate.execute();

        System.out.printf("Updated account:\n%s", updatedAccount.toPrettyString());



1 Expert replyverified_user

Java: Unable to update notifications for mybusiness account

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Could someone please help me with this.


Java: Unable to update notifications for mybusiness account

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

More information about the scenario:

1) I am developer for the project created by our company.

2) I am trying to check the API with the credentials(accesstoken/secret) that collected for our clients businesses. 


Let me know if you need more details.


Marked as Best Answer.
Accepted by topic author Vinod Reddy S
October 2016

Re: Java: Unable to update notifications for mybusiness account

[ Edited ]
Google Employee
# 4
Google Employee

Hi @Vinod Reddy S,


Please navigate to the Pub/Sub topics page in the Cloud Platform Console to make sure that you have Created a topic, Given it publish permissions, Created a subscription and Specified push or pull delivery flow. Please note that you can perform these aforementioned operations not only through sending requests, but also manually through the Cloud Platform Console UI.


According to the Publisher Guide, a topic you create is supposed to be in this format:



Please note that the “myproject” placeholder for the topic shown above should be the Project ID of your whitelisted project. Please use the correct format shown above for the topicName field of the Notifications object when sending the PUT request for updating the Google Cloud Pub/Sub notification settings for the specified account. Please note that the URI of this PUT request including the account_name of the specified account should be in this format:


I suggest you add this additional header to your requests to enable more detailed error messages in responses when using the Java client library:



You can also 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.


Here’s a code snippet to update the Google Cloud Pub/Sub notification settings for the specified account with the Java client library:


 * Updates the notification for an account.

 * @param name The name (account/`account_id`/notifications) for the notification

   to update.

 * @param topicName Google Cloud Pub/Sub topic name.

 * @throws IOException


 private static Notifications updateNotifications(String name, String topicName)

     throws IOException {

   Mybusiness.Accounts.UpdateNotifications updateNotifications =




               name + "/notifications", new Notifications().setTopicName(topicName));

   // 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.

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

   Notifications response = updateNotifications.execute();


   return response;





Java: Unable to update notifications for mybusiness account

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Thanks @Terry W , This line really helped in solving the issue

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