invoking service call out policy

ekumar
Participant II

HI

Is it possible to call or invoke service call out policy from javascript file which is in resources ?

requirement is i need to trigger different callout policies based on conditions so

0 1 149
1 REPLY 1

Hi @sai kumar

Yes and No.

You cannot invoke ServiceCallout directly from within JavaScript. That's not how the control logic works in an Apigee Edge . proxy.

You CAN set a variable within JavaScript and then specify conditions in the proxy to invoke the ServiceCallout. You need to set a variable in which you can set particular value(boolean, integer etc) and use that variable over your service call out a policy as a condition.

So in your javascript you can set flag named triggerVar

if (<add your condition over here>) {
  context.setVariable("triggerVar", "true");
}

And in your proxy endpoint use that variable as a condition to execute service call out

<PostFlow name="PostFlow">
  <Response>
    <Step>
      <Condition>triggerVar equals "true"</Condition>
      <Name>Service-Callout-Policy-Name</Name>
    </Step>
  </Response>
</PostFlow>

If you have many conditions then i would suggest use integer values like if value of variable is 1 then call Service-Callout-1 and if the value of the variable is 2 then call Service-Callout-2, and so on.

Hope this will helpful for you. Let me know if you have any query.