Google Business Profile API Returns Only Some Locations: Fix Pagination
This article focuses on Paginated location retrieval in a Google Business Profile integration.
By Chamko Research Team Updated 5 min read
Quick answer
This article focuses on Paginated location retrieval in a Google Business Profile integration.
Overview
This article focuses on Paginated location retrieval in a Google Business Profile integration.
Overview
A multi-location dashboard may show only the first set of locations returned by the Business Profile API even though the account manages more branches. A common cause is that the integration processes one page and ignores the nextPageToken field. The list method returns locations in pages, and the caller must request subsequent pages when a next-page token is present. The proper fix is to implement pagination correctly, preserve the query parameters required by the method, and test the result against accounts with more locations than fit on a single page.
How pagination works
A list response can contain a collection of locations, an approximate total count, and a token indicating that more results are available. The application uses the token from one response in the next request to continue the same listing operation. Page size controls the number of items requested per page within the method's supported limits. A response without a next-page token indicates that there are no more pages for that sequence. Do not treat a single page's item count as the complete account inventory unless the response confirms that the list has ended.
Inspect the current endpoint and response
The Business Profile API has different API versions and methods, and the exact page-size default and response fields can differ. Read the documentation for the endpoint actually used by the application. For example, the Business Information API location-list method documents pageToken, pageSize, and nextPageToken. Confirm that the code reads the correct response field name and does not confuse a total count with the number of items returned in the current page. Do not copy pagination logic from an unrelated Google API without checking its method contract.
Implement the page loop safely
Make the first request with the intended account, filter, ordering, read mask if required, and page size. Process the returned locations, then check whether nextPageToken exists. If it does, send another request using that token and the same logical query. Continue until the token is absent or an explicit safety limit is reached. Avoid infinite loops by detecting a repeated token and logging an error if the API returns an unexpected sequence. Keep each page's result in a temporary collection and publish the final inventory only after the retrieval completes successfully.
Preserve filters and ordering
A pagination bug can also appear when the first request uses a filter but later requests accidentally omit it or use a different account parent. The later page is part of the same logical listing operation, so preserve the parameters required by the method and use the returned token as documented. Do not manually invent page tokens or reuse a token from a different query. If the application allows operators to change the filter while a listing is in progress, cancel the old sequence and begin a new one rather than mixing pages from two different queries.
Compare counts without assuming exact equality
Some responses expose an approximate total count or a count related to the filtered result. Use it as a diagnostic signal, not as a replacement for pagination. The total can help identify a likely incomplete fetch, but filtering, account visibility, and concurrent changes can affect comparisons. Log the number of pages, locations retrieved, and whether a final page token remained. If the UI shows fewer locations than the API result, investigate local filtering, pagination, and database persistence separately. A complete API fetch can still be displayed incorrectly if the dashboard drops records later.
Test with small and large accounts
A useful test suite should include an account that returns one page, an account that returns multiple pages, an empty result, a filtered result, and a failure on a later page. Verify that the application does not declare success if page one worked but page two failed. Store partial progress for retry, but label the inventory incomplete until all required pages have been fetched. For very large portfolios, process pages in a controlled way and avoid launching duplicate full scans from multiple workers at the same time.
Example scenario
An agency dashboard lists exactly 100 branches for a portfolio known to contain more than 100 locations. The API request uses a page size of 100 and the response contains nextPageToken, but the application never makes a second call. The developer adds a token-driven loop, preserves the account and filter parameters, and adds a regression test with multiple mocked pages. The dashboard now marks the inventory complete only after the final response contains no next-page token.
Common mistakes
Do not assume the default page size means “return everything.” Do not use the total count as if it were a list of records. Do not change account or filter parameters midway through a page sequence. Do not discard the first page when a later request fails without recording partial progress. Avoid silently displaying an incomplete location list as complete. If the number of locations remains low after pagination is correct, investigate account type, access, filters, and the user's visibility in a separate diagnostic step.
Conclusion and next steps
When a location list appears incomplete, inspect the response for a next-page token and implement the documented pagination loop. Keep the account, filter, and ordering context consistent, detect repeated tokens, and test both single-page and multi-page responses. Report incomplete retrieval honestly and separate API fetching from any later filtering or display logic.
Operational checklist
Log page count, item count per page, final token presence, account parent, and filter used. Add an alert when a known portfolio's retrieved count changes unexpectedly. Use controlled retries for transient errors on later pages and avoid marking a partial scan as complete. Revisit the current API reference before relying on defaults, since methods can have different page-size limits and required fields.
Recovery when a later page fails
If the first page succeeds but a later page fails, do not label the inventory complete. Keep the already retrieved pages in a temporary job record and record which page failed. Retry a transient failure with bounded backoff; if a token is no longer usable, restart the listing sequence rather than stitching unrelated sequences together. The dashboard should show “refresh incomplete” and retain the last known complete inventory separately from the partial attempt. This protects operators from confusing a partial network result with a real reduction in branch count.
Design for changing inventories
A location can be added or removed while a large listing is in progress. Treat the list as a retrieval process rather than assuming the account cannot change during pagination. Where consistency matters, store retrieval timestamps and reconcile the final set against the previous completed inventory. Do not automatically delete local branch records merely because one partial run did not return them. Require a completed fetch and an explicit comparison before treating a location as absent.