Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Extract queryparams and values

Not applicable

How to extract all the queryaprams names and values in javascript.

I tried below snippent but unable to fetch value of that queryparam dynmically.

var queryParams = context.getVariable('request.queryparams.names');
var count = context.getVariable('request.queryparams.count');
var queryString = context.getVariable('request.querystring');
if(count > 0){
    var queryParamsArray = queryParams.toArray();
    var first = queryParamsArray[0].toString();
    print(context.getVariable('request.queryparam.type'));
    print(queryParams[first]);
     print(context.getVariable('request.queryparam['first']'));
}else{
    context.setVariable('badQuery',"false");
}

the print statement is not prinitng value of queryparam type. Any help would be really appreciated

Solved Solved
1 3 6,687
1 ACCEPTED SOLUTION

@akshay.anand9 ,

Here you go,

var count = context.getVariable('request.queryparams.count');
if (count > 0) {
    var queryString = context.getVariable('request.querystring');
    var queryParamsArray = queryString.split("&");
    var queryParamsArrayLength = queryParamsArray.length;
    for (var i = 0; i < queryParamsArrayLength; i++) {
        var queryParamArray = queryParamsArray[i].split("=");
        print("Query Param Key :" + queryParamArray[0]);
        print("Query Param Value :" + queryParamArray[1]);
    }
}else{
    context.setVariable('badQuery',"false");
}

View solution in original post

3 REPLIES 3