401 Unauthorized on NICE CXone OAuth Token Endpoint via Python Requests

Getting a 401 Unauthorized response when trying to fetch an access token from the NICE CXone OAuth endpoint. The goal is to automate some REST calls using Python requests instead of the official SDK for a quick script.

Here is the setup:

import requests
import base64

client_id = 'my_client_id'
client_secret = 'my_client_secret'

# Basic Auth header
credentials = f"{client_id}:{client_secret}"
encoded_credentials = base64.b64encode(credentials.encode()).decode()

headers = {
 'Authorization': f'Basic {encoded_credentials}',
 'Content-Type': 'application/x-www-form-urlencoded'
}

data = {
 'grant_type': 'client_credentials'
}

url = 'https://platform.devtest.nice-incontact.com/oauth/token'

response = requests.post(url, headers=headers, data=data)
print(response.status_code)
print(response.text)

The response is consistently:

{
 "error": "invalid_client",
 "error_description": "Client authentication failed"
}

I’ve verified the client ID and secret in the developer portal. They look correct. I tried switching to requests.auth.HTTPBasicAuth just in case the manual base64 encoding was off, but same result.

Is the endpoint different for the devtest environment? Or is there a specific scope I need to pass in the body even for client credentials? The docs are vague on this part.

Also, I noticed the production endpoint uses platform.nice-incontact.com. Should I be hitting that instead for dev? Don’t want to mess up prod configs.

Basic auth on the token endpoint is the issue. Switch to application/x-www-form-urlencoded with grant_type, client_id, and client_secret in the body.

import requests

url = "https://platform.api.niceincontact.com/oauth/token"
payload = {
 "grant_type": "client_credentials",
 "client_id": "my_client_id",
 "client_secret": "my_client_secret"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
print(response.json())