Attention: v4.7 of the API has released! See change log. Posts related to COVID-19 are still temporarily permitted for chains.

Work with account data

This tutorial shows you how to work with account data. The Google My Business API provides you with the ability to do the following:

  • List all accounts.
  • Return a specific account.
  • Update an account.

Before you begin

Before you use the Google My Business API, you need to register your application and obtain OAuth 2.0 credentials.

For details on how to get started with the Google My Business API, see Basic setup.

List all accounts

A great way to validate the accounts associated with an authenticated user is to list all their accounts. Use the accounts.list API to list all accounts associated with a user.

To list all the accounts for an authenticated user, use the following:


The following function uses Mybusiness.Accounts.List to return a list of accounts.

 * Returns a list of accounts.
 * @return List A list of accounts.
 * @throws Exception
public static List listAccounts() throws Exception {
  Mybusiness.Accounts.List accountsList = mybusiness.accounts().list();
  ListAccountsResponse response = accountsList.execute();
  List accounts = response.getAccounts();

  for (Account account : accounts) {
  return accounts;

Return a specific account

Sometimes, you only want to see information about a specific account for an authenticated user. Use the accounts.get API to return a specific account and review additional account details.

To return a specific account by name, use the following:

$ GET{accountId}

This function uses Mybusiness.Accounts.Get to return the data for a single account.

 * Demonstrates getting an account by name.
 * @param accountName The name (resource path) of the account to retrieve.
 * @return Account The requested account.
private static Account getAccount(String accountName) throws Exception {
  Mybusiness.Accounts.Get account =
  Account response = account.execute();

  return response;

Additional data

The Java Client Library gives you access to additional field data for account instances. Use the following methods to return additional data about the account:

  • getAccountName()
  • getName()
  • getRole()
  • getState()
  • getType()

Update an account

Changing an account name is a fundamental administrative task. Use the accounts.update API to alter the account name.

To update a specific account by name, use the following:

$ PUT{accountId}

  "account": {
    "accountName": "Anne Droyd"
  "languageCode": "en",
  "validateOnly": "true"

This function uses Mybusiness.accounts.update to update the accountName field for a business account.

 * Updates a field for a business account.
 * @param accountName The name (resource path) of the account to update.
 * @param newAccountName A string containing the updated value.
 * @throws IOException
private static void updateAccount(String accountName, String newAccountName) throws IOException {
  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());


  • The only editable field for an account is accountName. Any other fields passed are ignored.
  • Only accounts of BUSINESS type can be updated in this manner.