CXone Studio GetRESTProxy auth failing with 401

Hi all,

I’m trying to call the CXone API from within a Studio snippet to fetch some user data, but I keep hitting a 401 Unauthorized error. I know the endpoint is correct because I can hit it from Postman using the same client ID and secret.

The issue seems to be how I’m handling the authentication token generation inside the script. I’m using GetRESTProxy to make the initial token request to https://api.cxp.nice.com/platform/oauth2/token. I’ve set the content type to application/x-www-form-urlencoded and the body to grant_type=client_credentials&client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET.

Here’s the snippet I’m using for the token request:

ASSIGN restProxy = GetRESTProxy("tokenRequest")
ASSIGN restProxy.Method = "POST"
ASSIGN restProxy.Uri = "https://api.cxp.nice.com/platform/oauth2/token"
ASSIGN restProxy.ContentType = "application/x-www-form-urlencoded"
ASSIGN restProxy.Body = "grant_type=client_credentials&client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET"
ASSIGN tokenResponse = restProxy.Execute()

When I log tokenResponse.Status, it’s returning 200, and I can see the access_token in the response body. I then extract the token and try to use it in a second GetRESTProxy call to fetch user details:

ASSIGN userProxy = GetRESTProxy("userRequest")
ASSIGN userProxy.Method = "GET"
ASSIGN userProxy.Uri = "https://api.cxp.nice.com/platform/v2/users/me"
ASSIGN userProxy.Headers.Authorization = "Bearer " + tokenResponse.Body.access_token
ASSIGN userResponse = userProxy.Execute()

This is where it fails. userResponse.Status is 401. I’ve double-checked that the token is being passed correctly in the header. Is there something specific about how CXone Studio handles OAuth tokens that I’m missing? Maybe the token expires too quickly or there’s a scope issue? I’ve tried adding scope=users:read to the token request body but that didn’t help either.

Any ideas on what I’m doing wrong here?