Dynamically passing null

Not applicable

Currently having issues passing null in Apigee e.g. I have an Apigee façade that calls a micro service, and it returns a valid JSON with a variable equal null, I want to then pass that null onto the caller. I do extract variable then assign message to create my client payload.

Issue is that if I try pass null, when it sends the response back to the caller, it malformed the JSON.

What I would expect is that if null, I’d get back {“test”: null, “test”: “test”} but instead I get {“test”: , “test”: “test”}.

I can probably create the response in JS and pass that to the client, but I was wondering if there was a trick to doing this with extract and assign?

0 2 115
2 REPLIES 2

I couldn't figure out a nice way to get a null to come in as a null apart from using AssignMessage to set the whole payload... e.g.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Response">
    <DisplayName>Assign Response</DisplayName>
    <Properties/>
    <Copy source="calloutResponse">
        <Payload/>
    </Copy>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

So, I think javascript to modify the callout response is probably the cleanest. Depends on what you want to do specifically, but I tried just removing an element from the callout response like so:

 var r = JSON.parse(context.getVariable("calloutResponse.content"))
 delete r.message
 context.setVariable("calloutResponse.content", JSON.stringify(r))

and nulls in the callout response JSON came through correctly to the proxy response. Still pretty clean, just one more simple JS policy in the flow. ¯\_(ツ)_/¯

Hi Carlos,

Thanks for your reply.

I ended up using JS to create the payload, grabbed the necessary data from flow variables, generated the JSON object then passed back to Apigee as a custom attribute. I needed to do a few things in the Apigee layer prior to returning to client, used assign message for the client response injecting in the JS payload.

This ended up doing the trick nicely, although I would like to see Apigee support injection of null when dynamically injecting a value in assign message, if the value of a requested value is null, it should pass in null.