In the My Business Notifications API, the Cloud Pub/Sub topic you register with
accounts.updateNotificationSetting
must belong to the same Google Cloud project as the OAuth 2.0 client making the
request. Supplying a topic from a different project returns 400
INVALID_ARGUMENT with reason PUBSUB_TOPIC_NOT_IN_CALLER_PROJECT.
While the topic must live in your API client project, Cloud Pub/Sub subscriptions and subscriber workloads can live in any Google Cloud project. Use one of the two patterns on this page when your notification consumers run in a separate project from your Business Profile API credentials.
Choose a cross-project pattern
| Pattern | Where the subscription lives | When to use |
|---|---|---|
| Cross-project subscription | Consumer project (PROJECT_B) |
PROJECT_B manages its own push endpoints, BigQuery or Cloud Storage export subscriptions, dead-letter topics, or belongs to a separate team. |
| Cross-project subscriber account | API client project (PROJECT_A) |
A service account in PROJECT_B pulls messages directly and does not need to manage subscription settings in PROJECT_B. |
Option 1: Cross-project subscription
In this setup, PROJECT_A owns the OAuth 2.0 client and the Pub/Sub topic, and
PROJECT_B owns the subscription attached to that topic.
1. Enable APIs
Enable the Cloud Pub/Sub API (pubsub.googleapis.com) in both PROJECT_A and
PROJECT_B, and enable the My Business Notifications API
(mybusinessnotifications.googleapis.com) in PROJECT_A.
2. Create the topic in your API client project
Create the topic in PROJECT_A and grant
mybusiness-api-pubsub@system.gserviceaccount.com the Pub/Sub Publisher role
(roles/pubsub.publisher) on that topic:
gcloud pubsub topics create TOPIC_ID --project=PROJECT_Agcloud pubsub topics add-iam-policy-binding TOPIC_ID \ --project=PROJECT_A \ --member="serviceAccount:mybusiness-api-pubsub@system.gserviceaccount.com" \ --role="roles/pubsub.publisher"
3. Grant cross-project subscription permissions
To attach a subscription in PROJECT_B to the topic in PROJECT_A, the
principal creating the subscription needs:
pubsub.subscriptions.createonPROJECT_B(included inroles/pubsub.editororroles/pubsub.admin).pubsub.topics.attachSubscriptionon the topic inPROJECT_A(included inroles/pubsub.subscriber,roles/pubsub.editor, orroles/pubsub.admin).
Grant that principal the roles/pubsub.subscriber role on the topic in
PROJECT_A:
gcloud pubsub topics add-iam-policy-binding TOPIC_ID \
--project=PROJECT_A \
--member="PRINCIPAL" \
--role="roles/pubsub.subscriber"Replace PRINCIPAL with the user or service account that creates the
subscription, for example user:admin@example.com or
serviceAccount:SUBSCRIBER_SA@PROJECT_B.iam.gserviceaccount.com.
4. Create the subscription in the consumer project
In PROJECT_B, create a pull, push, or export subscription that references the
topic in PROJECT_A:
gcloud pubsub subscriptions create SUBSCRIPTION_ID \
--project=PROJECT_B \
--topic=TOPIC_ID \
--topic-project=PROJECT_A5. Register the topic
Authenticate with OAuth 2.0 credentials from PROJECT_A and call
accounts.updateNotificationSetting
with the topic in PROJECT_A:
PATCH https://mybusinessnotifications.googleapis.com/v1/accounts/{accountId}/notificationSetting?updateMask=pubsubTopic,notificationTypes
{
"name": "accounts/{accountId}/notificationSetting",
"pubsubTopic": "projects/PROJECT_A/topics/TOPIC_ID",
"notificationTypes": ["NEW_REVIEW", "UPDATED_REVIEW", "GOOGLE_UPDATE"]
}
Option 2: Cross-project subscriber account
If PROJECT_B only needs to pull messages, you can keep both the topic and the
subscription in PROJECT_A and grant PROJECT_B's worker service account
roles/pubsub.subscriber on the subscription:
gcloud pubsub subscriptions create SUBSCRIPTION_ID \ --project=PROJECT_A \ --topic=TOPIC_IDgcloud pubsub subscriptions add-iam-policy-binding SUBSCRIPTION_ID \ --project=PROJECT_A \ --member="serviceAccount:WORKER_SA@PROJECT_B.iam.gserviceaccount.com" \ --role="roles/pubsub.subscriber"
Your worker in PROJECT_B then pulls from
projects/PROJECT_A/subscriptions/SUBSCRIPTION_ID while PROJECT_A registers
projects/PROJECT_A/topics/TOPIC_ID with accounts.updateNotificationSetting.
Migrate an existing cross-project topic
If your account currently points at a topic in PROJECT_B while your API calls
authenticate with an OAuth 2.0 client in PROJECT_A, migrate without dropping
notifications:
- Create a new topic in
PROJECT_Aand grantmybusiness-api-pubsub@system.gserviceaccount.comroles/pubsub.publisheron it as shown in step 2. - Attach a new subscription in
PROJECT_Bto the topic inPROJECT_Aby following step 3 and step 4, and start your consumers on the new subscription while keeping your existing subscription running. - For each Business Profile account that sends notifications to the old
topic, call
accounts.updateNotificationSettingusingPROJECT_A's OAuth 2.0 client to updatepubsubTopictoprojects/PROJECT_A/topics/TOPIC_ID. - Wait for any in-flight messages on the old subscription to drain, then delete the old subscription and topic.
Troubleshooting
| Error reason | Cause and fix |
|---|---|
PUBSUB_TOPIC_NOT_IN_CALLER_PROJECT |
The project segment in pubsubTopic (projects/{project}/topics/{topic}) does not match the Cloud project that owns the OAuth 2.0 client making the request. Create the topic in your OAuth client's project and use a cross-project subscription for consumers in other projects. If the request sets a quota project, for example with the X-Goog-User-Project header, use the project number of the OAuth client's project in pubsubTopic instead of the project ID. |
PUBLISH_PERMISSIONS_MISSING_FOR_PUBSUB_TOPIC |
mybusiness-api-pubsub@system.gserviceaccount.com lacks pubsub.topics.publish on the topic. Grant roles/pubsub.publisher on the topic in PROJECT_A. |
INVALID_PUBSUB_TOPIC |
The topic name is not formatted as projects/{project}/topics/{topic}, or the topic does not exist in Cloud Pub/Sub. |