Rotating OAuth Client Secrets in Python SDK without dropping active WFM queries

Hey folks,

I’m trying to figure out the best way to rotate our OAuth client secrets for the Genesys Cloud Python SDK without causing downtime for our WFM adherence scripts. We have a few long-running processes that pull real-time agent status and service level metrics, and I can’t afford to have them fail mid-execution just because the secret changed.

The official docs mention that you can have two active secrets at a time, but I’m a bit confused on the exact sequence of API calls needed to make this smooth. I’ve tried just updating the secret in the portal and restarting the script, but that obviously causes a gap in data collection.

Here’s what I have so far in my Python script:

from _platform_client import PlatformApi

configuration = PlatformApi.Configuration(
 host='https://api.mypurecloud.com',
 client_id='my_client_id',
 client_secret='old_secret_123'
)

api_instance = PlatformApi(configuration)

If I just swap client_secret to the new one, the existing tokens become invalid immediately, right? I need to generate a new token with the new secret while the old one is still valid for active requests.

I tried calling POST /api/v2/oauth/token manually with the new secret, but I’m not sure how to inject that new token back into the PlatformApi instance without creating a whole new instance and potentially losing state. Also, do I need to explicitly deactivate the old secret via PATCH /api/v2/oauth/clients/{id} before the rotation is complete?

Any code examples showing how to handle this token refresh cycle programmatically would be great. I’m just trying to keep my adherence logs continuous.