Manage real-time notifications

In Google My Business API, notifications are published in conjunction with Google Cloud Pub/Sub. Before enabling notifications, you need to follow the get started guide to set up Google Cloud Pub/Sub and create a topic.

After a topic is created, you can perform the following operations on notifications:

Get started

  1. Follow the Google Cloud Pub/Sub guide to set up your application.
  2. Create a topic in your Google Cloud Pub/Sub Project and note the name of the created topic.
  3. Give at least publish permissions to mybusiness-api-pubsub@system.gserviceaccount.com.
  4. Set up either push or pull notifications by following the Subscriber Guide to set up a notification in Google Cloud Pub/Sub.
  5. Using the topic name you created in Google Cloud Pub/Sub, link your Google My Business account to the topic by calling the Account.updateNotifications endpoint in the Google My Business API and begin receiving notifications.
  6. (Optional) Repeat step 5 for each Google My Business account you want to receive notifications for.

Retrieve notification settings

Gets the Google Cloud Pub/Sub notification for the account.

accounts.getNotifications

HTTP

To get the pub/sub notification for the account, send a GET request using a URL of the following form:

https://mybusiness.googleapis.com/v4/accounts/account_name/notifications
Java

This function uses Mybusiness.Accounts.getNotifications to return the data for the accounts notification.

/**
 * Demonstrates getting notification data.
 * @param name The name (account/`account_id`/notifications) for the notification to retrieve.
 * @returns response The notification data.
 */
private static GetNotifications getNotifications(String name) throws Exception {
  Mybusiness.Accounts.getNotifications sub =
      mybusiness.accounts().getNotifications(name);
  GetNotifications response = sub.execute();

  return response;
}

Update notification settings

Updates the Google Cloud Pub/Sub notification setting.

accounts.updateNotifications

HTTP

To update notification settings, send a PUT request using a URL and request body of the following form:

https://mybusiness.googleapis.com/v4/accounts/account_name/notifications

{
  name: your/pubsub/topicName
}

If no notification settings exist, they will be created.

Java

This function uses Mybusiness.accounts.updateNotifications to update the notification settings for a business account.

/*
 * 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 UpdateNotifications updateNotifications(String name, String topicName) throws IOException {
  Notification notification = new Notification()
    .setName(topicName);
  MyBusiness.Accounts.UpdateNotification updateNotification =
    mybusiness().accounts().updateNotification(name, notification);

  UpdateNotification response = updateNotification.execute();

  return response;
}

Delete notification settings

Deletes the Google Cloud Pub/Sub notification settings.

accounts.deleteNotifications

HTTP

To delete notification settings, send a DELETE request using a URL of the following form:

https://mybusiness.googleapis.com/v4/accounts/account_name/notifications
Java

This function uses Mybusiness.Accounts.DeleteNotifications to clear the notification settings.

/**
 * Demonstrates deleting the Google Cloud Pub/Sub settings.
 * @param notificationName The name (account/`account_id`/notifications) for the notification settings to delete.
 * @returns The deleted notification setting.
 */
private static DeleteNotifications deleteNotifications(String notificationName) throws Exception {
  Mybusiness.Accounts.DeleteNotifications toDelete =
      mybusiness.accounts().deleteNotifications(notificationName);
  DeleteNotification response = toDelete.execute();

  return response;
}

Send feedback about...

Google My Business API
Google My Business API
Need help? Visit our support page.