CXone client_credentials token refresh failing with 401

Hey folks,

Trying to automate some CXone API calls using the client_credentials grant. The initial token fetch works fine, but I’m hitting a wall when the token expires. My script isn’t handling the refresh properly.

Here’s the flow:

  • Fetching token from https://api.nice-incontact.com/oauth2/token
  • Using the access token for /api/v2/contacts
  • Getting a 401 Unauthorized after ~30 minutes

I’ve checked the client ID and secret. They are correct. Am I missing a step in the refresh logic?

Cause: client_credentials tokens don’t have refresh tokens. You can’t refresh them.
Solution: Fetch a new token on every 401. Cache it for 25 minutes to save calls.

curl -X POST https://api.nice-incontact.com/oauth2/token \
 -d "grant_type=client_credentials&client_id=$ID&client_secret=$SECRET"