Business Profile API Access Token Expires During a Long Sync: Implement Refresh Correctly
This article focuses on Access-token refresh and long-running jobs in a Google Business Profile integration.
By Chamko Research Team Updated 5 min read
Quick answer
This article focuses on Access-token refresh and long-running jobs in a Google Business Profile integration.
Overview
This article focuses on Access-token refresh and long-running jobs in a Google Business Profile integration.
Overview
A long-running sync can begin successfully and then fail partway through because the access token expires. The correct solution is to manage token lifetime as part of the request lifecycle, not to ask users to reconnect every time a job runs for several minutes. Use the supported OAuth token-refresh process, handle refresh failures distinctly from API failures, and make each job resumable. Keep refresh tokens secure and avoid launching several simultaneous refresh requests for the same connection when a single refresh can serve multiple workers.
Understand the token lifecycle
Business Profile API requests require an OAuth access token. Access tokens are short-lived, while refresh tokens may allow the application to obtain new access tokens when permitted. The application should not assume an access token remains valid for the full duration of a batch job. Nor should it assume that a refresh token will always work forever: user revocation, client configuration changes, and account conditions can invalidate the authorization. Keep the token lifecycle separate from the health of the business profile itself.
Refresh before the request fails when practical
If the token response includes an expiry time, track it and refresh before a planned operation when the token is close to expiry. Leave a safety margin for clock skew and long network calls. Do not refresh on every request without reason, because that adds overhead and can create races. A central token manager can check the expiry, refresh when needed, and provide a valid access token to workers. If the API still returns an authentication error, classify it and follow the documented recovery path rather than repeatedly sending the same expired token.
Avoid refresh races
In a multi-worker system, several jobs may notice that the same access token is expiring and all attempt to refresh it at once. Coordinate refresh operations per user connection using a lock, single-flight mechanism, or equivalent concurrency control. Store the new token result atomically so a worker cannot overwrite a newer token record with stale state. Keep the refresh operation's result separate from each individual API request. This prevents token refresh from becoming a source of intermittent failures in large sync jobs.
Handle refresh failure separately
A temporary network error during token refresh may be retried with a bounded policy. An invalid_grant response is different: the stored grant may no longer be usable and the user may need to authorize again. Mark that connection as requiring reauthorization and stop background jobs for it. Do not label every failed request as a token-expiry problem; a 403, 429, or server error needs its own handling. Good error classification keeps the dashboard's message accurate and prevents unnecessary reconnect prompts.
Make long syncs resumable
Do not keep all progress only in memory while a job runs. Record completed pages or locations and the current checkpoint. If a token expires or the network fails, refresh or reconnect as appropriate and resume unresolved work. Before retrying a write, determine whether the earlier attempt may already have succeeded. For multi-location updates, store completion per operation and location. This avoids restarting a large sync from the beginning and reduces the risk of duplicate side effects.
Secure the token store
Keep refresh tokens on the server and protect them with access controls and encryption appropriate to the environment. Do not send them to browser code, analytics systems, or customer-visible logs. Limit which services can read or update the token record. Record metadata such as expiry time, last successful refresh, and connection status without recording the token itself. When a user disconnects the integration, stop scheduled jobs and remove or revoke stored authorization through the appropriate supported process.
Example scenario
A chain syncs 400 locations overnight. The first 150 succeed, then the access token expires and later calls fail. The old worker restarts the entire job and repeatedly sends the expired token. The improved system detects expiry, obtains a fresh access token through the stored refresh grant, and resumes from the last confirmed location. If refresh returns invalid_grant, the connection is marked as needing user consent and the job pauses. The dashboard reports partial completion rather than claiming that all locations failed.
Testing checklist
Test a token that remains valid, a token that expires mid-job, a refresh network timeout, a revoked refresh token, and multiple workers refreshing the same connection. Verify that the job resumes without duplicate writes and that the user receives a reconnection request only when needed. Confirm that token values never appear in logs. Use mocked token responses for most failure scenarios and a real authorised connection only for a controlled integration test.
Conclusion and next steps
Treat access-token refresh as a shared connection service rather than logic copied into each API call. Track expiry, refresh with a safety margin, coordinate concurrent workers, distinguish invalid grants from transient failures, and checkpoint long jobs. Protect refresh tokens and resume only unresolved work. This approach makes Business Profile integrations more reliable without repeatedly interrupting business owners.
Operations dashboard indicators
Track time until access-token expiry, last successful refresh, number of refresh attempts, rejected grants, jobs waiting for reauthorization, and syncs paused because of authentication. Alerts should identify the affected connection without exposing credentials. A dashboard that separates token lifecycle from API quota and profile status helps support teams explain the issue correctly and route it to the right person.
Token expiry should not corrupt batch status
If a token expires after a subset of operations succeeds, keep each operation's state rather than marking the whole batch failed. Distinguish completed, retryable, and waiting-for-reauthorization items. Once a new token is available, resume only eligible work and preserve the original job identifier for auditing. If the application cannot determine whether a write succeeded before the connection failed, read the resource state first where the API supports it. This prevents token management from causing duplicate updates or misleading completion totals.
Coordinate refresh with job scheduling
Scheduled jobs should consult the same connection manager instead of implementing independent refresh logic. A shared policy can enforce expiry margins, refresh locking, secure storage, and error classification. If a refresh is already in progress, another worker can wait for its result rather than starting a competing token exchange. Monitor refresh latency and failure rates separately from Business Profile API request latency; this makes it clear whether the bottleneck is OAuth or the profile service itself.