I’ve been banging my head against this for two days and the documentation isn’t quite clear on the exact syntax for digging into complex JSON payloads returned by the GetRESTProxy action. I am building a custom lookup in a Studio script that needs to fetch user profile data from an external .NET API and then map specific fields to session variables.
The API call itself works fine. I get a 200 OK. The issue is extracting the data. The response body is a nested JSON object. Here is the structure I am getting back:
{
"data": {
"profile": {
"tier": "platinum",
"lastLogin": "2023-10-27T10:00:00Z"
},
"status": "active"
},
"metadata": {
"requestId": "abc-123"
}
}
I am using the GetRESTProxy action to make the call. I store the result in a variable called restResult. When I try to access the tier, I have tried several variations in the ASSIGN action, but they all result in a null value or a script error.
I’ve tried this:
{{restResult.data.profile.tier}}
And this:
{{restResult['data']['profile']['tier']}}
Neither works. The restResult variable seems to contain the raw JSON string, but I can’t figure out how to treat it as a proper object within the Studio expression engine. Do I need to use a separate action to deserialize the JSON first? Or is there a specific function like JSON.parse() available in the expression context that I am missing?
Also, if the external API returns a 500 error, how do I gracefully handle that in the flow without crashing the entire script? Right now the script just stops and the caller gets hung up on. I need to set a fallback value if the lookup fails.
Any pointers on the correct syntax for accessing nested properties in Studio snippets would be great. I feel like I am missing something obvious here.