How to extract comma separated queryparameter values from url using javascript

Dear @Pranjali Shrivastava ,

Welcome to Apigee Community.

Are you talking about general Javascript or Extracting variables in context to Apigee Edge API Proxy flows ? If it’s just javascript please refer to Stack Overflow. General programming questions are off-topic in Apigee Community.

Cheers,

Anil Sagar

Hi @Pranjali Shrivastava,

If you are looking to access queryparameters using javascript in Edge, please refer to this link: http://apigee.com/docs/api-services/reference/javascript-object-model

Extract from above link:

queryParams

The request message query parameters as a mapping of String =>List.

Examples:
"?city=PaloAlto&city=NewYork"can be accessed as:

context.proxyRequest.queryParams['city'];  // == 'PaloAlto'
context.proxyRequest.queryParams['city'][0]     // == 'PaloAlto'
context.proxyRequest.queryParams['city'][1];    // == 'NewYork' 
context.proxyRequest.queryParams['city'].length(); // == 2  

And like Anil mentioned, once you have extracted the values, for parsing the comma separated values please refer to javascript general programming.

Hope this helps.

Here is a quick snippet to show how to approach this within a Javascript Callout:

var multiValuedParam = context.getVariable("request.queryparameter.foo");
var values = multiValuedParam.split(','),
    result = [];

values.forEach(function(value) {
    var decodedValue = decodeURIComponent(value);
    result.push(decodedValue);
});

context.setVariable("result", JSON.stringify(result));

Thanks for the help. But considering URL queryparameter be like-

?city=PaloAlto,NewYork,Austin

how can i extract them now

Once you get the value “PaloAlto,NewYork,Austin” in a variable using context.proxyRequest.queryParams[‘city’]; , you can use general javascript code to split them up.