Nouh Belahcen
Nouh Belahcen

Reputation: 854

PUBLISH_PERMISSIONS_MISSING_FOR_PUBSUB_TOPIC Error Despite Correct Pub/Sub Permissions

I'm integrating the Google My Business API with Google Cloud Pub/Sub to subscribe to notifications for new reviews. Despite setting up the necessary permissions, I keep encountering the following error when trying to update the notification settings:

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "PUBLISH_PERMISSIONS_MISSING_FOR_PUBSUB_TOPIC",
        "domain": "mybusinessnotifications.googleapis.com"
      }
    ]
  }
}

Here’s what I’ve done so far:

  1. Pub/Sub Topic Setup:
  1. OAuth2 Token:
  1. API Request:
async function subscribeToGMBNotifications(accountId, accessToken) {
  const url = `https://mybusinessnotifications.googleapis.com/v1/accounts/${accountId}/notificationSetting?updateMask=pubsubTopic,notificationTypes`;

  const payload = {
    name: `accounts/${accountId}/notificationSetting`,
    pubsubTopic: `projects/my-project/topics/gmb-reviews`,
    notificationTypes: ['NEW_REVIEW'],
  };

  try {
    const response = await fetch(url, {
      method: 'PATCH',
      headers: {
        Authorization: `Bearer ${accessToken}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(payload),
    });

    if (response.ok) {
      const data = await response.json();
      console.log('Subscription successful:', data);
      return data;
    } else {
      const errorData = await response.json();
      console.error('Subscription error:', errorData);
      return null;
    }
  } catch (error) {
    console.error('Network error:', error);
    return null;
  }
}
  1. Verified Pub/Sub IAM Policy:

Despite setting everything up as described, I keep getting the PUBLISH_PERMISSIONS_MISSING_FOR_PUBSUB_TOPIC error. Could there be something I’m missing in the setup, or is there an additional permission or configuration required for the Google My Business API to publish to Pub/Sub?

Any insights or suggestions would be greatly appreciated!

Upvotes: 0

Views: 320

Answers (3)

Pavan
Pavan

Reputation: 345

Here you need to add Pub/Sub Publisher permission to topic NEW_REVIEW. Here's how to fix it:

1. Go to the Google Cloud Console: Open the Google Cloud Console and navigate to your project that contains the Pub/Sub topic.

2. Find your Pub/Sub topic: Go to the Pub/Sub section and locate the topic projects/my-project/topics/gmb-reviews.

3. Edit permissions:

  • Click on the topic to view its details.
  • Find the "Permissions" tab.
  • Click "Add Principle" to add a new member. enter image description here

4. Add the service account:

  • In the "New Principle" field, enter [email protected].

  • Select the role "Pub/Sub Publisher" from the dropdown.

  • Click "Save".

New Principle

Now follow https://developers.google.com/my-business/reference/notifications/rest/v1/accounts/updateNotificationSetting

Upvotes: 0

pavan kumar
pavan kumar

Reputation: 335

@nouh belahcen

please provide "Healthcare Service Agent" role to the topic  for "[email protected]"

your issue will be resolved

Upvotes: 0

Dhiraj Singh
Dhiraj Singh

Reputation: 536

The error message "PUBLISH_PERMISSIONS_MISSING_FOR_PUBSUB_TOPIC," that means that the service account you used to set up the subscription does not have the necessary rights to publish messages to the Pub/Sub topic.

You must grant the service account the required IAM roles and permissions in order to fix this problem. You must specifically provide the service account access to the "Pub/Sub Publisher" role on the newly established Pub/Sub topic.

Further steps to give the service account the "Pub/Sub Publisher" role and more details can be found in this documentation. Hope, this might help you.

Upvotes: 0

Related Questions