Reputation: 854
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:
Pub/Sub Publisher
role to the service account ([email protected]).https://www.googleapis.com/auth/business.manage
scope.PATCH
method to update the notification settings with the following 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;
}
}
Pub/Sub Publisher
and Pub/Sub Admin
roles.
Question: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
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:
4. Add the service account:
In the "New Principle" field, enter [email protected].
Select the role "Pub/Sub Publisher" from the dropdown.
Click "Save".
Upvotes: 0
Reputation: 335
@nouh belahcen
please provide "Healthcare Service Agent" role to the topic for "[email protected]"
your issue will be resolved
Upvotes: 0
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