Access Javascript variable in Service Callout ploicy

Not applicable

Hi,

I want to access Javascript variable into Service Callout Policy. How can I do that.

Solved Solved
0 7 662
1 ACCEPTED SOLUTION

In javascript callout set a variable using below command...

context.setVariable("myName", "AnilSagar");

In service callout access variable using syntax like below..

    <HTTPTargetConnection>
        <URL>http://google.com/{myName}</URL>
    </HTTPTargetConnection>

View solution in original post

7 REPLIES 7

In javascript callout set a variable using below command...

context.setVariable("myName", "AnilSagar");

In service callout access variable using syntax like below..

    <HTTPTargetConnection>
        <URL>http://google.com/{myName}</URL>
    </HTTPTargetConnection>

@Anil Sagar

I am able to set the variable using context.setVariable.

But I want to add this variable in the JSON payload that I send in ServiceCallout.

What I tried is this:

<Payload contentType="application/json" variablePrefix="%" variableSuffix="#"> {"username":"###", "serial":"###", "keyId":"###", "otp":{otp}}

</Payload>

I am unable to fetch the otp that has been set in javascript using context.setVariable("otp","12345");

You have set the variable prefix and suffix.

Use..

%otp#

..instead of..

{otp}

Let us know if it works!

@apigee1234567 What error do you see in trace ? On Api Call ?

@Anil Sagar Sean Davis answered the question. Since I had used variable prefix and suffix, I am supposed to write %otp# and not {otp}.

@apigee1234567 Awesome, Glad your issue is resolved. Thank you @Sean Davis

this is cruel guys, you never explained fully how the prefix and suffix are used? Is it in the header, Incredible how unhelpful this is.

Prakash