VariableAccess in ServiceCallout Policy

Hi, I have a requirement to access the variables available in session in Payload of ServiceCallout Policy. But I didn’t find any examples/documents related to that. Please share the docs or examples to use the access variables in Payload.

Example: Suppose If I wanted to pass the ‘apiproxy.name’ in the subject variable in JSON Payload of ServiceCallout. What is the syntax to use it?

Ex ServiceCallout:

application/json POST {“from”:“test”,“to”:“test1”,“subject”:“Test Subject email”,“html”:“Test body email”} calloutResponse 60000 http:/test.apigee.net/v1/abc

1 Like

Swapna, have you looked at the AssignMessage policy here:

http://apigee.com/docs/api-services/reference/assign-message-policy

Stephen

Hi @Swapna

Following change should help in this scenario: “subject”:“%apirpoxy.name#”

As @sgilson has suggested, AssignMessagePolicy provides much more flexibility. In fact, ServiceCallout being a generic scenario, recommendation is to use three policy in the sequence; AssignMessage,ServiceCallout, and ExtractVariables. Following resources may be helpful:

  1. http://apigee.com/docs/api-services/cookbook/using-policy-composition

Sample code is available here:

https://github.com/apigee/api-platform-samples/tree/master/doc-samples/policy-mashup-cookbook

Cheers, Rajesh Doda

@sgilson Thanks for your quick response.

How I can use those assign variables in the payload of ServiceCallout? The below syntax is not working to get variable “ProxyName” to pass it in the JSON Payload. Please advice.

Example: AssignMessage

AssignVariablesToSendMail

ProxyName

apiproxy.name

Example: ServiceCallout

{“Name”: ProxyName}

Thanks @rdoda I have used the same syntax to get the variables available from session. But it was displayed as string. Mostly all the variables are available in session, so is there anyway that I can access them directly in service callout policy?

Used:

Payload contentType=“application/json” variablePrefix=“%” variableSuffix=“#”> {“from":"abc@gmail.com,“to”:"xyz@gmail.com",“subject”:“Test Subject email”,“html”:“@apiproxy.name#”}

Output:

@apiproxy.name#

You should look at the example here:

http://apigee.com/docs/api-services/cookbook/using-policy-composition

It has a complete example of adding a variable to a request to ServiceCallout.

You seem to be mixing the two ways to pass a variable to the Service Callout. Either create a new request object in the AssignMessage policy containing the variable and pass that to Service Callout, or use the Payload option in Service Callout.

I got it now. We have use the “variablePrefix” and “variableSuffix” properties of the payload and use these two properties to get the value.

Saw it in the below link.

https://community.apigee.com/articles/2458/how-do-i-easily-insert-variables-into-json-payload.html

Thanks!

@sgilson. Thanks it’s working now.

Good to know that you are able to resolve with this post.

@Swapna I am glad that your issue is resolved. could you please accept the answer that helped you? It helps others in the community as well. Thanks!