Pregunta

I am doing a URL rewrite in my API End point. So, the querystring is not passed by default to the backend service.

I want to create a variable with name "querystring" and format that string with the input query params. How can I do that?

For eg: apigee api url = https://myapigee-prod.agigee.net/v1/test/resource1?p1=abc&p2=123

I want to create the querystring variable as querystring = param1=abc&param2=123

I tried

<AssignVariable>
    <Name>myqs</Name>
    <Value>param1={request.queryparam.p1}&amp;param2={request.queryparam.p2}</Value>
</AssignVariable>

<Ref> tag can be used instead of <Value> tag only if I am getting value of one parameter. To form a string, it wouldn't work.

¿Fue útil?

Solución

Unfortunately you can't use the curly braces method of variable expansion within an AssignVariable.

You can do this via a JavaScript policy. Here is the JavaScript code:

var myqs = "param1=" + context.getVariable("request.queryparam.p1") +
    "&param2=" + context.getVariable("request.queryparam.p2");
context.setVariable("myqs", myqs);               

Otros consejos

Also, you can use an AssignMessage policy to do this, on the Proxy request or Target request flow.

http://apigee.com/docs/api-services/content/generate-or-modify-messages-using-assignmessage

e.g.

<AssignMessage name="GenerateRequest">
<AssignTo createNew="false" type="request">Request</AssignTo>
<Set>
<QueryParams>
  <QueryParam name="p1">{request.queryparam.param1}</QueryParam>
  <QueryParam name="p2">{request.queryparam.param2}</QueryParam>
</QueryParams>
</Set>
</AssignMessage>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top