CXone Studio Snippet: GetRESTProxy 500 Error on JSON Parse

Hey folks,

I’m hitting a wall with a Studio script that needs to fetch some external data via REST. The flow works fine up until the snippet tries to parse the response. I’m getting a 500 Internal Server Error in the flow execution log, but the API call itself seems successful.

Here’s the setup: I have a Studio flow that triggers a snippet. The snippet uses GetRESTProxy to hit a simple internal endpoint that returns a JSON object with a status code and a message. The endpoint is verified to work via Postman. The issue is strictly in how Studio handles the response parsing.

Here is the snippet code:

string apiUrl = "https://api.internal.example.com/status";
string restResponse = GetRESTProxy(apiUrl, "GET", null, null);

// This is where it fails
object jsonResponse = ConvertJsonToDictionary(restResponse);
string status = jsonResponse["status"].ToString();

if (status == "active") {
 SetFlowVariable("isActive", true);
} else {
 SetFlowVariable("isActive", false);
}

The error log in Genesys Cloud says: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary'2'.

I know GetRESTProxy returns a string. I thought ConvertJsonToDictionary would handle the conversion, but it seems like it’s choking on the raw string or maybe the JSON structure isn’t what it expects. I’ve tried wrapping the response in Newtonsoft.Json.JsonConvert.DeserializeObject, but Studio snippets don’t seem to allow importing external DLLs easily without a custom assembly, which I’d prefer to avoid if possible.

Is there a built-in way to parse JSON in a Studio snippet without throwing this cast exception? Or is the restResponse string formatted in a way that needs cleaning before conversion? I’ve checked the raw response string in a debug log, and it looks like valid JSON: {"status": "active", "message": "OK"}.

Any ideas on how to fix this parsing step?

The 500 error usually means the JSON structure doesn’t match what the parser expects, not that the HTTP call failed. Check if your response includes a wrapper object or unexpected whitespace. Studio’s JSON parser is strict about keys. If the external API returns {"data": {"status": 200}} but you’re trying to read status directly, it’ll crash. Also, ensure the Content-Type header is explicitly set to application/json in the REST Proxy configuration. Sometimes the server sends text/html even with valid JSON, which breaks the implicit type conversion in the snippet. Try adding a ParseJSON step before accessing the fields. Here’s a safe pattern:

// Inside the Studio Snippet
var proxy = GetRESTProxy();
var response = proxy.Execute();
if (response.StatusCode == 200) {
 // Explicitly parse to handle potential whitespace or wrapper issues
 var payload = ParseJSON(response.Body); 
 // Check structure before accessing
 if (payload.data && payload.data.status) {
 SetFlowData("apiStatus", payload.data.status);
 }
}

Verify the raw body in the debug log. It’s often a missing field causing the null reference exception.

is spot on. The parser in Studio is notoriously picky about nested objects. I’ve seen this exact 500 error when the response wraps data inside a result or payload key, and the snippet tries to access the root level directly.

If you’re using the GetRESTProxy action, double-check that your Response configuration in the snippet actually maps to the correct JSON path. Don’t just leave it at the default. You might need to use a JSONPath expression like $.data.status instead of just status.

Also, verify the Content-Type header. If your external endpoint returns text/plain or application/octet-stream, Studio won’t auto-parse it as JSON. Force the header in the request config if you can.

Here’s a quick snippet to test if the structure is the issue:

// Inside your Studio Snippet
var response = GetRESTProxy();
try {
 // Force parse to see the raw structure
 var parsed = JSON.parse(response.Body);
 LogMessage("Raw Response: " + JSON.stringify(parsed));
} catch (e) {
 LogMessage("Parse Failed: " + e.message);
}

Check the logs. That’ll show you exactly where the mismatch is.