Multi-Location Posting
List the Google Business Profile locations an account manages, post to several of them in one request and switch the account's default location.
When you finish this page you have published one post to several Google Business Profile (googlebusiness) locations from a single connected account, and switched the location that account posts to by default. You need a connected account (accountId) whose Google login manages more than one location.
Step 1: list the locations
Call GET /v1/accounts/{accountId}/gmb-locations (List locations). It returns up to 100 locations and the one currently selected; pass search to filter by business name or raise limit (max 500) for larger accounts.
import Zernio from '@zernio/node';
const zernio = new Zernio();
const { data: locations } = await zernio.connect.getGmbLocations({
path: { accountId: '66b2e19d8c3f5a7e9d0b1c2d' }
});
console.log(locations.selectedLocationId, locations.locations);Response (200):
{
"locations": [
{
"id": "12345678901234567890",
"name": "Joe's Pizza Downtown",
"accountId": "accounts/123456789",
"accountName": "Joe's Pizza",
"address": "123 Main St, San Francisco, CA",
"category": "Pizza restaurant"
},
{
"id": "22345678901234567890",
"name": "Joe's Pizza Marina",
"accountId": "accounts/123456789",
"accountName": "Joe's Pizza",
"address": "45 Bay St, San Francisco, CA",
"category": "Pizza restaurant"
}
],
"hasMore": false,
"selectedLocationId": "12345678901234567890",
"cached": true
}Step 2: post to several locations
Repeat the platforms entry with the same accountId and a different platformSpecificData.locationId each time. The value is locations/ followed by the location's id from Step 1. An entry without locationId posts to the selected location.
const { data: published } = await zernio.posts.createPost({
body: {
content: 'Now open at both locations. Visit us today.',
mediaItems: [{ type: 'image', url: 'https://cdn.example.com/store.jpg' }],
platforms: [
{
platform: 'googlebusiness',
accountId: '66b2e19d8c3f5a7e9d0b1c2d',
platformSpecificData: { locationId: 'locations/12345678901234567890' }
},
{
platform: 'googlebusiness',
accountId: '66b2e19d8c3f5a7e9d0b1c2d',
platformSpecificData: { locationId: 'locations/22345678901234567890' }
}
],
publishNow: true
}
});
console.log(published.post.platforms.map((p) => p.platformPostUrl));Response (201), one platforms entry per location:
{
"post": {
"_id": "65f1c0a9e2b5af0012ab34cd",
"status": "published",
"platforms": [
{ "platform": "googlebusiness", "status": "published", "platformPostUrl": "https://business.google.com/..." },
{ "platform": "googlebusiness", "status": "published", "platformPostUrl": "https://business.google.com/..." }
]
}
}Step 3: switch the default location
Call PUT /v1/accounts/{accountId}/gmb-locations with selectedLocationId to change which location the account posts to when locationId is omitted (Update location). Pass googleAccountId (the accountId resource name from Step 1) as well, so the location is resolved directly instead of by enumerating the account; large accounts require it.
const { data: switched } = await zernio.connect.updateGmbLocation({
path: { accountId: '66b2e19d8c3f5a7e9d0b1c2d' },
body: { selectedLocationId: '22345678901234567890', googleAccountId: 'accounts/123456789' }
});
console.log(switched.selectedLocation.name);Response (200):
{
"message": "Google Business location updated successfully",
"selectedLocation": {
"id": "22345678901234567890",
"name": "Joe's Pizza Marina"
}
}To give each location its own profile (one profile per client, as an agency would), Assign location to another profile connects a location onto a different profile by reusing this account's OAuth grant, with no second browser flow.
If it fails
A 400 on PUT /v1/accounts/{accountId}/gmb-locations means selectedLocationId is not one of the locations this Google login manages, or googleAccountId is not one of its accounts:
{
"error": "Location not in available locations",
"type": "invalid_request_error"
}Take the id and accountId values from Step 1 rather than typing them, then retry. A 404 means accountId is not one of your connected accounts. Error handling covers the envelope.
Related
- List locations:
search,filterandlimitfor accounts with many locations. - Assign location to another profile: one profile per client without a second OAuth.
- Posts & Content Types: the base request.
- Inbox: reviews across several locations in one call.
- Profiles: how profiles group accounts.
Event & Offer Posts
Publish event and offer posts to Google Business Profile with topicType, and set the post language with languageCode.
Business Profile Management
Read and update a Google Business Profile listing through the API, with hours, verification, photos, attributes, action links, services and food menus.