Just noticed that my CXone Studio snippet is failing to extract nested JSON values from a REST API call. I am building a self-hosted automation pipeline where an n8n workflow triggers a CXone interaction, and I need to fetch user profile data via the CXone REST API within the Studio flow. The GET request succeeds, but the subsequent parsing logic in the ASSIGN block throws a null reference error.
Here are the steps to reproduce the issue:
- Define a
GetRESTProxyaction with the endpointhttps://api.nice-incontact.com/ccapi/v2/users/{userId}. - Set the HTTP method to
GETand include the OAuth2 Bearer token in the headers. - Execute the request. The debug log shows a
200 OKstatus with a valid JSON payload. - Add an
ASSIGNblock to parse the response body into a local variable usingjson_decode(). - Attempt to access a nested property, such as
user.profile.email, in a subsequentIFcondition.
The code snippet for the ASSIGN block looks like this:
// Parse the raw response body
assign parsedResponse = json_decode(restResponse.body);
// Attempt to extract email
assign userEmail = parsedResponse.profile.email;
The error message in the Studio debug console is: NullReferenceException: Object reference not set to an instance of an object at line 4.
I have verified that the restResponse.body contains the expected JSON structure:
{
"id": "12345",
"profile": {
"email": "[email protected]",
"name": "John Doe"
}
}
Despite this, parsedResponse appears to be null or malformed when passed to the next step. I suspect the issue might be related to how json_decode handles the string format returned by GetRESTProxy, or perhaps the variable scope is not persisting correctly between the REST action and the ASSIGN block. Has anyone encountered similar issues with nested object parsing in CXone Studio snippets? Is there a specific syntax I should use to safely access nested properties?