Get value of url request parameter to do a test

Hi, I am trying to get a value from the get request params. I found that pm.request.url.query.all() creates an array of objects with the url params. So I tried the following:
let queryParams = pm.request.url.query.all();

So this gets the parameters and when I console log it shows them in object and key / value pairs. Then I need to get a specific value of a property with the following function:

console.log(queryParams.find(function(element) {
    return element.hasOwnProperty("from");
}).from);

There is a property β€œfrom” with value: 2019-08-15. I see it when I console.log the queryParams variable. But when I console.log the above function it returns β€œnull”.

Please advise if I am missing something here.

Thank you,

Hey @nikolay100,

Welcome to the community! :slight_smile:

You could just try something like this:

console.log(pm.request.url.query.toObject().from)

3 Likes

This worked great. Thanks. Somebody should put this in the documentation, because I could not find it anywhere.

This solution is not working can something else to use for toObject().from) ?
Also, url is set are from environment variables
When use. console.log(request.url);
I get this output
{{urlwfsservice}}/v1/merchantorders/{{orderId}}/BoardingActivities.updateMerchantToHub.REQUEST/details/
how can I get output like below simpleurl ?
var simpleurl = β€œhttps://dev-someweburl.com/v1/merchantorders/ZN2aB/BoardingActivities.updateMerchantToHub.REQUEST/details/”;

@aerospace-explorer-2 I see a similar post here.

pm.variables.replaceIn() method should help you :blush:

That solution was specific to the other users’ context. :smiley:

The URL contains variables so you would need to resolve them:

console.log(pm.variables.replaceIn(pm.request.url.toString()))
2 Likes