In the Google My Business API, notifications are published in the Cloud Pub/Sub service. After you set up Cloud Pub/Sub and create a topic, you can perform the following operations on notifications:
New or updated reviews, questions and answers, media uploads, Google updates for review, location state changes, and more are supported. The NotificationType object lists and describes the available notification types.
Before you begin
To use the Google My Business API, register your application and obtain OAuth 2.0 credentials. For details on how to get started with the API, see Basic setup.
Cloud Pub/Sub setup
To set up Google My Business API notifications with Cloud Pub/Sub, perform the following steps:
- Follow the Cloud Pub/Sub guide to set up your application.
- Create a topic in your Cloud Pub/Sub project and note the name of the created topic.
- Give at least
pubsub.topics.publish
permissions to mybusiness-api-pubsub@system.gserviceaccount.com. - Follow the Subscriber overview guide to set up either push or pull notifications.
- To receive notifications, call the
accounts.updateNotifications
endpoint in the Google My Business API. In the call, use the topic name you created in Cloud Pub/Sub to link your GMB account to the topic. - (Optional) Repeat step 5 for each Google My Business account that you want to receive notifications for.
Retrieve notification settings
The accounts.getNotifications
endpoint returns the current Cloud Pub/Sub notification settings for an
account. The following table shows how to call it in HTTP and Java:
GET https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications
The following 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. * @return 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
The accounts.updateNotifications
endpoint updates the Cloud Pub/Sub notification settings associated with an
account. The following table shows how to call it in HTTP and Java:
PUT https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications { name: your/pubsub/topicName }
The following function uses Mybusiness.Accounts.Locations.Reviews.Get
.
/** * Demonstrates getting a review by name. * @param reviewName The name (resource path) of the review to retrieve. * @return Account The requested review. */ private static Review getReview(String reviewName) throws Exception { Mybusiness.Accounts.Locations.Reviews.Get review = mybusiness.accounts().locations().reviews().get(reviewName); Review response = review.execute(); return response; }
Delete notification settings
The accounts.deleteNotifications
endpoint deletes the Cloud Pub/Sub notification settings from an account.
The following table shows how to call it in HTTP and Java:
DELETE https://mybusiness.googleapis.com/v4/accounts/{accountId}/notifications
The following function uses Mybusiness.Accounts.DeleteNotifications
.
/** * Demonstrates deleting the Google Cloud Pub/Sub settings. * @param notificationName The name (account/`account_id`/notifications) for the notification settings to delete. * @return 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; }