Hey everyone,
I’m trying to inject trace context into our Studio flows by hitting a custom internal service. I’ve set up a Snippet action to make the HTTP call using GetRESTProxy, but I’m hitting a wall trying to parse the nested JSON response back into Studio variables.
Here’s the setup. I’m calling an endpoint that returns a simple structure with a traceId and some metadata. The HTTP request itself works fine-I get a 200 OK. The issue is extracting the value.
Snippet code:
<action name="GetTraceContext">
<set var="req">
<json>
{"sessionId": "{{sessionId}}"}
</json>
</set>
<set var="res">
<http:post url="https://my-internal-api.corp/trace" body="{{req}}" />
</set>
<set var="traceId">
<json:parse json="{{res}}" path="$.data.traceId" />
</set>
</action>
The response body looks like this:
{
"status": 200,
"data": {
"traceId": "abc-123-def",
"parentSpan": "xyz-789"
}
}
When I run this, traceId comes back empty. I’ve tried $.data.traceId, $.data["traceId"], and even just $.traceId assuming it flattens, but nothing works. The json:parse tag seems to choke on the nested object structure.
Is json:parse in Snippets limited to flat JSON only? I know we can use Data Actions for complex logic, but I need this sync within the script to propagate the context immediately to subsequent API calls.
Any ideas on how to drill down into that data object properly?