Hitting a snag with our Jenkins pipeline running on a server in Chicago. The build script uses a Kotlin script to fetch an OAuth token from /api/v2/oauth/token using the client credentials grant. The token works fine for the first few minutes, but then the subsequent API calls to update routing configurations start failing with 401 Unauthorized. The token expires after the default 3600 seconds, which is too short for our nightly deployment job that can run for 45 minutes.
I tried requesting a longer-lived token by adding a expires_in parameter, but the API ignores it and returns a standard 1-hour token. Is there a way to get a token that lasts longer than an hour without refreshing it in the script? I’d rather not implement a full refresh token flow in this simple Kotlin script if I can avoid it.
Here’s the relevant part of the Kotlin code:
val response = HttpPost("https://api.mypurecloud.com/api/v2/oauth/token")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.setBody("grant_type=client_credentials&client_id=${clientId}&client_secret=${clientSecret}")
.execute()
val token = response.jsonBody["access_token"]
The response looks like this:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "admin:all"
}
I checked the developer docs but didn’t see an obvious way to extend the lifetime for client credentials. Do I need to use a different grant type or is there a hidden parameter I’m missing?