ServiceCallout FormParam on a condition

Not applicable

Is it possible to add a FormParam only when a condition is satisfied?


For e.g. if I have:

<Request clearPayload="false" variable="req" type="application/x-www-form-urlencoded">
        <Set>
            <Headers>
                <Header name="Content-Type">application/x-www-form-urlencoded</Header>
            </Headers>
            <FormParams>
                <FormParam name="abcID">{Order.UniqueTransactionID}</FormParam>
                <FormParam name="apiUsername">{TN.PA.UserName}</FormParam>  
	   </FormParams>
        </Set>
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
 </Request>

And if want to add my abcID to the request only if the Order.UniqueTransactionID (which is set by an assignmessage policy) is not empty or null. Is it possible?

0 3 473
3 REPLIES 3

yes it's possible, but not within a single policy. What I suggest is that you separate the _assignment_ of the request properties from the _transmission_ of the request to the external service.

For example.

<Step> 
  <Name>AM-BaseMessage</Name>
</Step>
<Step>
  <Name>AM-AppendABCID</Name>
  <Condition> Order.UniqueTransactionID != null</Condition>
</Step>
<Step> 
  <Name>SC-MakeExternalCall</Name>
</Step>

And then...

The first policy should set the new request message

<AssignMessage name='AM-BaseMessage'>
  <AssignTo createNew='true' transport='http' type='request'>newMessage</AssignTo>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Set>
    <Headers>
      <Header name="Content-Type">application/x-www-form-urlencoded</Header>
    </Headers>
    <FormParams>
      <FormParam name="apiUsername">{TN.PA.UserName}</FormParam>  
    </FormParams>
  </Set>
</AssignMessage>

the second policy adds another form param:

<AssignMessage name='AM-AppendABCID'>
  <AssignTo createNew='false'>newMessage</AssignTo>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Set>
    <FormParams>
      <FormParam name="abcID">{Order.UniqueTransactionID}</FormParam>
    </FormParams>
  </Set>
</AssignMessage>

And then finally the Service callout

<ServiceCallout name='SC-MakeExternalCall'>
  <Request clearPayload="false" variable="newMessage"/>
  <Response>scResponse</Response>
  <HTTPTargetConnection> 
     ....
  </HTTPTargetConnection>
</ServiceCallout>

Hi Dino,

Have faced this scenario multiple times where we had to use multiple AssignMessage policy just to add some conditions... or alternatively we had to use javascript policy.

It would be ideal if we could add conditions in the Assign Message itself. Do you see that this kind of enhancement will come in the near future.

Regards

Sibi

Hi Sibi

I cannot think of a single policy that includes conditional logic, aside from the logic that you can embed in JavaScript or Python etc.

So I think that it is unlikely that Apigee will introduce conditional branching inside a policy, even the AssignMessage policy.