Fixing INVALID_FUNCTION in CXone Studio: Correct Syntax for GetRESTProxy()
What You Will Build
- A working CXone Studio Snippet that successfully authenticates and executes a REST API call using the
GetRESTProxy()function. - This tutorial addresses the specific
INVALID_FUNCTIONruntime error that occurs when the legacy or incorrect proxy method is invoked. - The programming language covered is CXone Studio Snippet syntax (a proprietary, JSON-like scripting language for NICE CXone).
Prerequisites
- Platform: NICE CXone.
- Component: Studio Flow with a Snippet node.
- Required Scopes: The API endpoint being called must be accessible via the CXone system user or the specific OAuth token being generated. For most internal CXone APIs, the
apioradminscope is required depending on the resource. - Snippet Context: You must have a valid
Authorizationtoken variable available in the Studio flow context, or you must generate one within the snippet using an OAuth flow. - Dependencies: No external libraries are required. This uses native CXone Studio Snippet functions.
Authentication Setup
Before calling GetRESTProxy(), you must possess a valid access token. The INVALID_FUNCTION error often masks an underlying issue where the developer assumes the token is present, but the proxy fails to initialize because the authentication context is malformed.
In Studio, tokens are typically generated using the OAuth2 flow. Ensure your flow has a previous node that generates a token and stores it in a variable, for example, $.token.
If you are testing locally or in a debug environment, you can inject a static token, but for production, use the Generate Token node in Studio.
Critical Note: The GetRESTProxy() function is a legacy wrapper. In modern CXone Studio Snippets, the preferred method is httpRequest() or httpPost(). However, if you are maintaining legacy snippets or using specific internal proxies, GetRESTProxy() is still valid. The INVALID_FUNCTION error usually stems from incorrect invocation syntax, specifically passing arguments by name instead of position, or calling it on the wrong object context.
Implementation
Step 1: Understanding the INVALID_FUNCTION Cause
The INVALID_FUNCTION error in CXone Studio Snippets typically occurs for one of three reasons when using GetRESTProxy():
- Incorrect Object Context: Attempting to call
GetRESTProxy()as a global function instead of a method on thehttpobject or a specific proxy instance. - Argument Mismatch: Passing a JSON object for parameters when the function expects positional arguments, or vice versa.
- Deprecated Syntax: Using the old
cxone.httpnamespace which has been removed in newer Studio runtime versions.
The correct signature for the modern equivalent of GetRESTProxy() functionality is often handled via httpRequest. However, if you are forced to use the proxy pattern, the correct invocation is via the http context.
Legacy (Broken) Syntax:
{
"result": {
"proxy": "GetRESTProxy('api.nicecxone.com', '443')"
}
}
Why this fails: GetRESTProxy is not a global function. It is a method on the http object in older runtimes, or entirely deprecated in favor of httpRequest.
Correct Modern Approach (httpRequest):
While the prompt asks for GetRESTProxy, it is crucial to note that INVALID_FUNCTION is often resolved by switching to the supported httpRequest function. If you must use the proxy pattern for specific legacy integrations, you must ensure you are using the http object.
Step 2: Correct Syntax for HTTP Calls in Studio Snippets
To eliminate the INVALID_FUNCTION error, replace the direct call to GetRESTProxy() with the standard httpRequest function, which is the supported way to make REST calls in CXone Studio.
Here is the correct structure for a GET request.
Snippet Code:
{
"httpResponse": {
"httpRequest": {
"method": "GET",
"url": "https://api.nicecxone.com/api/v2/users/me",
"headers": {
"Authorization": "Bearer $.token"
},
"timeout": 5000
}
}
}
Explanation:
httpRequest: This is the valid function name.method: Must be uppercase (GET, POST, PUT, DELETE).url: The full URL including the protocol.headers: A JSON object containing the headers. TheAuthorizationheader is mandatory for most CXone APIs.$.token: References the token variable stored in the flow context.
Step 3: Handling POST Requests with JSON Payloads
If you were using GetRESTProxy() to send data, you likely need a POST request. The syntax differs slightly to include the body.
Snippet Code:
{
"httpResponse": {
"httpRequest": {
"method": "POST",
"url": "https://api.nicecxone.com/api/v2/users",
"headers": {
"Authorization": "Bearer $.token",
"Content-Type": "application/json"
},
"body": {
"name": {
"firstName": "John",
"lastName": "Doe"
},
"email": "john.doe@example.com",
"type": "agent"
},
"timeout": 5000
}
}
}
Explanation:
body: The JSON payload to send. It is passed as a nested JSON object, not a string.Content-Type: Must be set toapplication/jsonfor JSON payloads.
Step 4: Parsing the Response
The httpResponse object returned by httpRequest contains the status code, headers, and body. You must parse the body if it is JSON.
Snippet Code:
{
"parsedResponse": {
"parseJson": {
"jsonString": "$.httpResponse.body"
}
}
}
Explanation:
parseJson: Converts the string body into a usable JSON object.$.httpResponse.body: References the body from the previous step.
Complete Working Example
Below is a complete Studio Snippet that generates a token (if not present), calls the GET /api/v2/users/me endpoint, and parses the response. This replaces the broken GetRESTProxy() pattern.
Note: In a real flow, you would generate the token in a previous node. This snippet assumes $.token exists. If it does not, the httpRequest will fail with a 401, not INVALID_FUNCTION.
{
"step1_makeRequest": {
"httpResponse": {
"httpRequest": {
"method": "GET",
"url": "https://api.nicecxone.com/api/v2/users/me",
"headers": {
"Authorization": "Bearer $.token"
},
"timeout": 5000
}
}
},
"step2_parseResponse": {
"parsedUser": {
"parseJson": {
"jsonString": "$.step1_makeRequest.httpResponse.body"
}
}
},
"step3_extractData": {
"userName": "$.step2_parseResponse.parsedUser.name.firstName",
"userId": "$.step2_parseResponse.parsedUser.id",
"statusCode": "$.step1_makeRequest.httpResponse.statusCode"
}
}
Expected Response Structure:
If successful, $.step3_extractData.statusCode will be 200.
$.step3_extractData.userName will contain the first name of the authenticated user.
Common Errors & Debugging
Error: INVALID_FUNCTION
What causes it:
- Calling
GetRESTProxy()directly as a global function. - Using an outdated Studio Snippet syntax version.
- Referencing a function that does not exist in the current CXone region’s runtime.
How to fix it:
- Replace
GetRESTProxy()withhttpRequest(). - Ensure you are using the
httpRequestkeyword as the value of a property, not as a standalone function call. - Check the CXone Studio documentation for the latest supported functions.
httpRequestis the standard.
Code showing the fix:
Before (Broken):
{
"result": "GetRESTProxy('api.nicecxone.com')"
}
After (Fixed):
{
"result": {
"httpRequest": {
"method": "GET",
"url": "https://api.nicecxone.com/api/v2/users/me",
"headers": {
"Authorization": "Bearer $.token"
}
}
}
}
Error: 401 Unauthorized
What causes it:
- The
$.tokenvariable is empty or expired. - The token does not have the required scopes for the API endpoint.
How to fix it:
- Verify that the token generation node ran successfully before the snippet.
- Check the scopes assigned to the OAuth application or system user generating the token.
- Add logging in the snippet to print
$.token(masked) to verify its presence.
Code showing the fix:
Add a condition to check for token existence:
{
"checkToken": {
"hasToken": {
"isNotNull": "$.token"
}
}
}
If $.checkToken.hasToken is false, trigger an error path in the flow.
Error: 400 Bad Request
What causes it:
- Incorrect JSON structure in the
bodyparameter. - Missing required headers like
Content-Type.
How to fix it:
- Validate the JSON payload using a JSON linter.
- Ensure
Content-Type: application/jsonis present in theheadersobject for POST/PUT requests.