CXone Studio Snippet: GetRESTProxy throwing INVALID_FUNCTION

I’m building a Studio snippet to fetch user profile data via the REST API, but I keep hitting an INVALID_FUNCTION error. I’ve got the snippet configured to accept a userId input. Here’s the code block:

var rest = GetRESTProxy("https://platform.niceincontact.com/api/v2/users/" + userId);
rest.SetHeader("Content-Type", "application/json");
rest.SetHeader("Authorization", "Bearer " + token);
var response = rest.Get();

The error points directly to the GetRESTProxy line. I’ve verified the base URL and the token variable is populated correctly earlier in the flow. I’ve also tried hardcoding a valid user ID just to rule out null input issues, but the error persists.

I know GetRESTProxy is supposed to handle the HTTP request, but the syntax feels off. Am I missing a specific parameter or is the endpoint format wrong for this proxy object? I’ve checked the CXone documentation and it’s pretty vague on the exact method signature for GET requests.

I’ve also tried using rest.Execute() but that just gives me a syntax error in the snippet editor. Anyone have a working example of a simple GET call using GetRESTProxy in a Studio snippet? I’ve been stuck on this for two hours.

The INVALID_FUNCTION error usually means the GetRESTProxy call isn’t resolving correctly or the environment doesn’t support that specific method signature. In CXone Studio, you often need to ensure the REST Proxy is initialized properly before calling methods on it.

Try breaking it down. First, initialize the proxy object. Then set headers. Finally execute the GET request. Also, check if userId is actually populated. If it’s null, the URL breaks and the SDK throws.

var url = "https://platform.niceincontact.com/api/v2/users/" + userId;
var rest = GetRESTProxy(url);

if (rest != null) {
 rest.SetHeader("Content-Type", "application/json");
 rest.SetHeader("Authorization", "Bearer " + token);
 var response = rest.Get();
 
 // Check response status
 if (response.StatusCode == 200) {
 var data = JSON.Parse(response.Body);
 // process data
 }
}

Make sure token is valid too. If it’s expired, you’ll get a 401, but the function call itself might fail if the proxy object is malformed. Double check the variable types in your snippet inputs.