Why does this setting of participant attributes via CXone Studio REST proxy fail to parse the JSON response? I am using the GetRESTProxy action to call an internal Salesforce endpoint. The HTTP status returns 200 OK, but the subsequent ASSIGN action throws a runtime error.
The snippet code attempts to map the response body directly to a session variable. The error log indicates a Type Mismatch when converting the raw string to a JSON object. My current snippet logic is below.
The simplest way to resolve this is to ensure the REST proxy action returns a string and explicitly cast it using JSON.parse() in the ASSIGN action, as Studio treats raw HTTP bodies as opaque strings by default. If the payload contains nested objects, verify that the Salesforce endpoint isn’t wrapping the response in an unexpected envelope that breaks the schema validation.
Check your expression syntax in the Assign action. The suggestion above mentions JSON.parse(), but docs state “JSON.parse is not available in Architect expressions.” that is why it fails. you cannot use standard JS functions there.
use the built-in json() function instead. it converts a JSON string to an object.
steps to fix:
ensure the REST Proxy action sets the response body to a variable, e.g., respBody.
in the Assign action, use json(respBody) to parse it.
access fields using dot notation, e.g., json(respBody).accountId.
docs say “the json() function parses a JSON-formatted string.” if you try to cast directly without json(), it throws a type mismatch because it stays a string.
also check if your Salesforce endpoint returns an array or a single object. if it is an array, you need json(respBody)[0].field. do not assume the root is an object. i got confused by this last week. my flow broke until i checked the raw response in the logs.
The documentation actually says you must treat the REST proxy response as a raw string before applying the json() function. I hit this exact wall last week while debugging a data action transform for a CRM integration. The issue isn’t just the missing function call; it is the implicit type casting failing because the response body contains trailing whitespace or BOM characters that break the parser.
Type Mismatch: Cannot convert string to object. Unexpected token in JSON at position 0
To fix this, do not map the response directly to an object variable. Map it to a string variable first, then use the json() function in a subsequent ASSIGN action to parse it. Here is the working expression pattern:
// Step 1: Assign raw string
set session.var.responseStr = action.response.body
// Step 2: Parse JSON safely
set session.var.parsedData = json(session.var.responseStr)
This ensures the parser receives a clean string. If your Salesforce endpoint returns an envelope, you might need to extract the specific node using JSONPath before parsing, but the json() wrapper is mandatory for the type conversion to succeed in Studio.
This is caused by implicit type coercion failing when the REST proxy response contains non-JSON whitespace or a BOM header. The suggestion above about using json() is correct in syntax, but it ignores the data integrity of the payload. Studio’s json() function is strict. If your Salesforce endpoint returns {"data": "val"}\n or {"data": "val"} , the parser throws a Type Mismatch error because it expects a pure JSON token stream. You must sanitize the input before parsing. Use trim() to remove whitespace. Then pass the clean string to json(). 1. Set a variable cleanBody with expression trim(getRESTProxyResponse.body). 2. In your ASSIGN action, use json(cleanBody) to create the object. 3. Access fields via dot notation, e.g., json(cleanBody).accountId. Skipping trim() is the most common reason for silent failures in Studio data actions. Do not rely on the HTTP 200 status to guarantee valid JSON structure. Validate the schema on the source side or handle errors in the flow.