Layer7 API Management

Expand all | Collapse all

Save All Query Parameters in multivalued variable

Jump to Best Answer
  • 1.  Save All Query Parameters in multivalued variable

    Posted 04-11-2017 01:45 AM

    How can we save the all Query Parameters into a multivalued variable?

    One solution is to Split the entire query string i.ie ${request.url.query}  by "&" . But this will fail when the data has "&" in it. Is there any other way to get the Query parameters in the variable?



  • 2.  Re: Save All Query Parameters in multivalued variable

    Posted 04-11-2017 04:29 AM

    Hi suhas.mv,

     

    Have you tried using the Map Value Assertion? 

    Map Value Assertion - CA API Gateway - 9.1 - CA Technologies Documentation 

     

    If this does not work for you, please can you give us an example of what you are trying to achieve.

     

    Regards

    Seenu Mathew



  • 3.  Re: Save All Query Parameters in multivalued variable

    Posted 04-11-2017 06:27 AM

    Hi Seenu_Mathew

    Thanks ! ,

    Below is an example of the requirement

    We have an API provided by a vendor as below.

    API URL : https://www.exmaple.com/v1/api/getdata?id=123456&type=vendor&email=example@gmail.com&data=sales&finance

    The API expects the values of the Query Param to be URL encoded.

    We tried passing the entire Query String for URL encoding, This will result in encoding of the "&" which is a delimiter of the Query parameter. And we don't want this to happen.

    So now we are trying as below

    •       Split the Query String by "&" to get an multi valued variable which has all the Query parameter.
      • multiValuedVariable[0] : id=123456
      • multiValuedVariable[1] : type=vendor
      • multiValuedVariable[2] : email=example@gmail.com
      • multiValuedVariable[3] : data=sales&finance
    • Iterate through Multi Valued variable  
      • Evaluate Regular Expression (.+=)(.+)  to get the value after "="
        • group 0 : data=sales&finance
        • group 1 : data=
        • group 2: sales&finance
      • Encode the value captured in group 2 i.e after encoding "sales%26finance"
      • Re join Group1+Encodedvalue to get data=sales%26finance and add in a multi valued variable
    • The multi-valued variable will be joined again using "&" to get back the query string 

    The Problem in this logic is that it splits "sales&finance" . Which is a not delimiter, but its part of the data/value. 



  • 4.  Re: Save All Query Parameters in multivalued variable
    Best Answer

    Posted 04-25-2017 03:58 PM
      |   view attached

    Good afternoon,

     

    From reviewing this post, I would suggest that if the & char will only appear in the data portion of the URL query then I would look to use a regular expression that reviews the entire URL query. I've included a policy that will do what I've outlined.

     

    Sincerely,

     

    Stephen Hughes

    Director, CA Support

    Attachment(s)

    zip
    encode_url_query.xml.zip   818B 1 version


  • 5.  Re: Save All Query Parameters in multivalued variable

    Posted 04-26-2017 12:37 AM

    Thanks Stephen !!

    Looks like you missed to attach the Policy ?



  • 6.  Re: Save All Query Parameters in multivalued variable

    Posted 04-26-2017 09:04 AM

    The policy is attachment below my previous post called encode_url_query.xml.zip. You will need to extract the policy file from the zip file.

     

    Sincerely,

     

    Stephen Hughes

    Director, CA Support



  • 7.  Re: Save All Query Parameters in multivalued variable

    Posted 05-03-2017 07:20 PM

    Hello suhas.mv,

    From my point of view, the problem here is that the URL is not properly URL encoded.

    If your URL is encoded like this,

    https://www.exmaple.com/v1/api/getdata?id=123456&type=vendor&email=example%40gmail.com&data=sales%26finance 

    There should be no problem to get the correct parameter value.

     

    ie. it's better to resolve this problem on client side.

     

    Regards,

    Mark