Trying to get the Python SDK to handle token refresh on its own. I’m building a WFM adherence checker that runs every minute. Right now, I’m manually calling client.set_access_token every hour, which feels wrong. The docs imply the SDK should do this automatically if I init it with the client ID and secret.
Here is my setup:
from platform.client import PlatformClient
client = PlatformClient()
client.set_configuration(
client_id='my-client-id',
client_secret='my-secret',
environment='mypurecloud.ie'
)
It still throws 401s after an hour. Am I missing a config flag?
from platform.client import PlatformClient
client = PlatformClient()
client.set_configuration(
client_id="your_client_id",
client_secret="your_client_secret",
environment="mypurecloud.com"
)
Stop calling set_access_token manually. That’s why it’s failing. The Python SDK handles the refresh token flow automatically if you initialize it with the client ID and secret. Just make sure you’re using a service account or a user with the right scopes, and don’t overwrite the token manually after init. The client keeps the session alive. If you’re still seeing 401s, check the scope list. You probably missed login:agent or routing:queue:view depending on what you’re pulling. Also, verify the client secret hasn’t rotated in the admin UI. Happens more often than you’d think. The SDK retries the refresh behind the scenes, so your WFM job should just work.