We’ve tried client.refresh() in the catch block, but the SDK instance still sends the old token. We’re pushing queue updates via /api/v2/routing/queues. The batch runs past the thirty-minute limit, so the job crashes with a 401 Unauthorized.
The snippet handles the error: client.refresh().then(() => { /* retry */ });. It gets the new token, but the next request fails immediately. The header isn’t updating.
The SDK doesn’t auto-swap headers on refresh like that. You need to manually set the new token in the client config before retrying, or just instantiate a fresh PureCloudPlatformClientV2 with the updated token.
const newToken = await client.refresh();
client.config.setAccessToken(newToken.access_token);
// now retry your /api/v2/routing/queues call
State drift happens if you don’t persist that token back to your state file too.