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?