Extract Variables from Multi Valued Params - S11E03

7002-everror1.png

I am getting null as my result in output from all transaction.I tried the same as you did it in the video can you please tell me why is it so? @Anil Sagar

0 4 605
4 REPLIES 4

Gee - you're going to need to provide more information.

  • what policy configuration are you using? Show it.
  • What is the context prior to the policy? Show the message content or the relevant context variables.

Remember: we are not magic. We cannot see your screen.

@Dino-at-Google , I believe OP is talking about this video here,

@Arun Prasath Sivanesan , Please share your proxy bundle & sample request you are making. Like @Dino-at-Google said, Above info is not enough to find out what is going on. We neither have access to your org / proxy nor your trace screen with request you are sending.

7005-everror2.png

7006-everror3.png

Thank you for responding

Hi Arun

I think you want to extract query parameters into variables.

First, you should be aware that query parameters are already available as context variables. Look in this documentation page and search for "request.queryparam". For example suppose your inbound request is expected to look like this;

GET /foo/bar?city=Cityname

Then you can reference the query param named "city" with this name:

request.queryparam.city

That will hold the value "Cityname" after the above inbound request.

If you want to retrieve multiple values, then you can dot-append an index. For example with this request:

GET /foo/bar?city=Mumbai&city=London

Then, you will get these values:

request.queryparam.city.1 Mumbai
request.queryparam.city.2 London

Having said that, you can use ExtractVariables to extract those same query parameters into other variables. I don't see the value in doing that, but you can do it. this policy:

<ExtractVariables name='EV-1'>
  <Source>request</Source>
  <VariablePrefix>extracted</VariablePrefix>
  <QueryParam name='city.1'>
    <Pattern ignoreCase='true'>{city1}</Pattern>
  </QueryParam>
  <QueryParam name='city.2'>
    <Pattern ignoreCase='true'>{city2}</Pattern>
  </QueryParam>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</ExtractVariables>

...when applied to the latter request above, will result in these variables being assigned:

extracted.city1 Mumbai
extracted.city2 London

If used with Query Parameters then the ExtractVariables is most useful for extracting some portion OUT of a query param, based on a pattern. For example suppose the qparam is not a city name but is a product code, which conforms to the pattern {category}-{stock number}, where {category} can be ABC or DEF, etc. And stock number is just a series of digits. Like this:

GET /foo/bar?code=ABC-18727

In that case you could do this:

<ExtractVariables name='EV-2'>
  <Source>request</Source>
  <VariablePrefix>extracted</VariablePrefix>
  <QueryParam name='code'>
    <Pattern ignoreCase='true'>{category}-{number}</Pattern>
  </QueryParam>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</ExtractVariables>

..then you would have these variable assignments:

extracted.category ABC
extracted.number 18727