Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Get Google Business Notifications from push Pub/Sub

Hello 😀

I'm trying to be notified when a new review is added on my Google Business Profile.

According to the documentation, I have setup the notification but I got nothing when a new review is added.

First of all, I have created a Pub/Sub Topic projects/my-project/topics/business-profile-notifications.

Then, I have created a Push subscription projects/my-project/subscriptions/business-profile-notifications-push attached to the previous created Topic. I have also defined an endpoint:  . This endpoint is listening POST requests

Finally, I have added the service account mybusiness-api-pubsub@system.gserviceaccount.com into IAM with Pub/Sub admin role.

On the code side, I'm using NPM googleapis client in a TypeScript Node.js server.

I'm updating the account settings to setup the notifications:

 

 

const { data }: GaxiosResponse<mybusinessnotifications_v1.Schema$NotificationSetting> = await google.mybusinessnotifications({
    version: 'v1',
    auth,
  }).accounts.updateNotificationSetting({
    name: `accounts/${params.accountID}/notificationSetting`,
    updateMask: 'notification_types',
    requestBody: {
      name: `accounts/${params.accountID}/notificationSetting`,
      pubsubTopic: 'projects/my-project/topics/business-profile-notifications',
      notificationTypes: [
        'NEW_REVIEW',
        'UPDATED_REVIEW',
      ],
    },
  });

 

 

At this point, nothing happens when a new review is added.

When I'm sending a POST request on my endpoint via curl command curl -X POST -H "Content-Type: application/json" -i "https://my-endpoint/webhook", the request is successfully catched.

In the other hand, when I'm getting notifications settings from the configured account, I have the notifications types but not any subscribed topic:

 

 

 

const {
  data,
}: GaxiosResponse<mybusinessnotifications_v1.Schema$NotificationSetting> = await google
  .mybusinessnotifications({
    version: "v1",
    auth,
  })
  .accounts.getNotificationSetting({
    name: `accounts/${accountID}/notificationSetting`,
    fields: "pubsubTopic,notificationTypes",
  });

 

 

 

Response:

 

 

 

{
  "notificationTypes": [
    "NEW_REVIEW",
    "UPDATED_REVIEW"
  ]
}

 

 

 

What I forgot to do ?

Solved Solved
3 4 1,954
1 ACCEPTED SOLUTION

I resolved the issue by myself 

In the documentation of updateNotificationSetting method, is it stated that "The only editable field is notificationSetting" about the updateMask field. But it's wrong. I had to add pubsubTopic as value.

Finally, the parameter values of this method are:

 

const opts = {
  name: `accounts/${params.accountID}/notificationSetting`,
  updateMask: 'notificationTypes,pubsubTopic',
  requestBody: {
    name: `accounts/${params.accountID}/notificationSetting`,
    pubsubTopic: params.pubsubTopic,
    notificationTypes: params.notificationTypes,
  },
};

const { data }: GaxiosResponse<mybusinessnotifications_v1.Schema$NotificationSetting> = await google.mybusinessnotifications({
  version: 'v1',
  auth,
}).accounts.updateNotificationSetting(opts);

 

View solution in original post

4 REPLIES 4

I resolved the issue by myself 

In the documentation of updateNotificationSetting method, is it stated that "The only editable field is notificationSetting" about the updateMask field. But it's wrong. I had to add pubsubTopic as value.

Finally, the parameter values of this method are:

 

const opts = {
  name: `accounts/${params.accountID}/notificationSetting`,
  updateMask: 'notificationTypes,pubsubTopic',
  requestBody: {
    name: `accounts/${params.accountID}/notificationSetting`,
    pubsubTopic: params.pubsubTopic,
    notificationTypes: params.notificationTypes,
  },
};

const { data }: GaxiosResponse<mybusinessnotifications_v1.Schema$NotificationSetting> = await google.mybusinessnotifications({
  version: 'v1',
  auth,
}).accounts.updateNotificationSetting(opts);

 

Hi, I'm kind of new working with pubsub. I'm trying to do exactly the same as described here but I got some doubts like, in this case you use the nodejs client library for changing the configuration of your pubsub topic but can I just hit the endpoint instead using postman? because I think is going to be a one time modification for me. Either way I think that my main question is how did you authorize the call with my business?

heyy i m tried uur solutiion but still not success,.

how long does it take from the time the review is made to the point you see them in pub/sub?