GetRESTProxy throwing INVALID_FUNCTION in CXone Studio Snippet

Trying to call an internal REST endpoint from a CXone Studio flow using a Snippet. The goal is to fetch user metadata before routing, but the script fails immediately on the proxy initialization.

Here’s the snippet code:

var proxy = GetRESTProxy();
var response = proxy.execute("GET", "/api/v2/users/me", {}, {});
SET("user_metadata", response.body);

The error log shows:
INVALID_FUNCTION: GetRESTProxy is not a valid function in this context.

I’ve checked the documentation and it clearly states GetRESTProxy() is available for outbound API calls within Studio. I’m using the latest Studio version. Is there a specific permission or flow type restriction I’m missing? The flow is triggered by a chat transfer.

I’ve also tried passing headers:

var headers = {"Authorization": "Bearer " + GET("access_token")};
var response = proxy.execute("GET", "/api/v2/users/me", {}, headers);

Same error. It’s like the function doesn’t exist. We’ve been using this pattern in other flows without issues, but this specific script keeps failing.

Checked the debug logs and the token is valid. The issue seems isolated to the function call itself.

Any ideas?

The INVALID_FUNCTION error usually means the Studio runtime doesn’t recognize the function name. In CXone Studio, it’s GetRESTProxy() for sure, but you’re likely running into a scope issue or a typo that got truncated in the log. Wait, looking closer at your code, GetRESTProxy is correct for CXone Studio snippets, but the execution context matters.

You can’t just call execute directly like that without handling the response object properly, and more importantly, you need to make sure the snippet is actually allowed to make outbound calls. But the immediate crash on initialization suggests the function isn’t exposed in your specific Studio version or environment config.

Try this pattern instead. It’s more solid and handles the proxy initialization explicitly:

try {
 // Initialize the REST proxy
 var proxy = GetRESTProxy();
 
 // Define the headers, especially Authorization if needed
 var headers = {};
 headers["Authorization"] = "Bearer " + GetAuthToken(); // Or pass token differently depending on setup
 
 // Execute the call
 var response = proxy.execute("GET", "/api/v2/users/me", headers, {});
 
 // Check if the call was successful
 if (response.statusCode == 200) {
 SET("user_metadata", response.body);
 SET("call_success", true);
 } else {
 SET("call_success", false);
 SET("error_msg", response.statusMessage);
 }
} catch (e) {
 SET("call_success", false);
 SET("error_msg", e.message);
}

Also, check your Studio project settings. Make sure “Allow REST Proxy” is enabled for the flow. If that’s on and it still fails, you might be hitting a sandbox restriction where /api/v2/users/me isn’t accessible from the snippet context because it tries to resolve the current user’s token which might be null in that isolated execution thread.

Try hitting a public endpoint first, like http://httpbin.org/get, to verify the proxy itself works. If that works, the issue is auth or scope. If that fails, it’s the proxy config.