CXone Studio Snippet: GetRESTProxy response parsing fails

Stuck on parsing a JSON response from a REST call inside a CXone Studio snippet. The GET request to our internal inventory service returns a 200 with valid JSON, but the snippet keeps failing to extract the stock count.

Here is the snippet code:

GetRESTProxy("inventory-check", "http://internal-api/stock?sku=" + $sku, "GET", "application/json", "")

IF($inventory-check.response.status_code == 200)
 ASSIGN($stock_count, $inventory-check.response.body.stock)
 LOG("DEBUG", "Stock count: " + $stock_count)
ELSE
 LOG("ERROR", "API failed: " + $inventory-check.response.status_code)
ENDIF

The debug log shows Stock count: undefined. Checking the raw response body in the trace, the JSON looks like {"sku": "ABC123", "stock": 5}. I’ve tried accessing it as $inventory-check.response.body["stock"] and even parsing the body string manually with a JSON parse function, but nothing sticks. The SDK docs are light on Studio-specific property paths. Is there a specific way to access nested objects in the response body object within the snippet engine? Or is the response body being returned as a string that needs explicit parsing before accessing properties?

You’re trying to access the body as a raw object. The REST Proxy action returns the body as a JSON string, not a parsed object. You need to parse it first or use the built-in JSON functions.

Try this:

ASSIGN($raw_body, $inventory-check.response.body)
ASSIGN($parsed_json, JSON.parse($raw_body))
ASSIGN($stock_count, $parsed_json.stock)

Also, check your status code comparison. $inventory-check.response.status_code is an integer. Compare it to 200, not "200". String comparison might fail depending on how the engine casts types.

If you’re still stuck, log $raw_body to a queue note or side conversation to see exactly what’s coming back. Sometimes internal APIs wrap the data in a data or result field.

Don’t assume the root object contains the field you want. Inspect the actual response payload.