Hi,
I'm creating a proxy that modifies a single field in a large json payload, before passing to the backend.
So I use the extract variable policy to extract the whole payload :
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Request-Data"> <DisplayName>Extract-Request-Data</DisplayName> <JSONPayload> <Variable name="body" type="nodeset"> <JSONPath>$ </JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">request</Source> <VariablePrefix>Request-Data</VariablePrefix> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </ExtractVariables>
Then I tried updating that variable with a assignmessage liek this:
<AssignMessage async="false" continueOnError="false" enabled="true" name="Update-Request-Message"> <DisplayName>Update-Request-Message</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignVariable> <Name>Request-Data.body.theField</Name> <Ref>Callout-Response-Data.body.fieldValue</Ref> </AssignVariable> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>
Unfortunately, the assign message has no effect. All I can see in the tracing is Request-Data.body.theField != (empty)
I also tried to do the update in a JS policy without luck.
Any advice on how this can be done? I don't want extract and copy 20 something fields just to update one field.
Thanks
Easiest thing to do is work directly with the content in a JavaScript policy. Something like:
var calloutBody = context.getVariable("Callout-Response-Data.content"); var calloutJson = JSON.parse(calloutBody); // make your changes context.setVariable("Callout-Response-Data.content", JSON.stringify(calloutJson));
User | Count |
---|---|
5 | |
2 | |
2 | |
1 | |
1 |