Query Parameters Are Automatically Added to Request URL

Hello everyone,

I can’t wrap my head around the behavior of my pm.request.url variable.
I want to send a POST request twice to the same url, that is why in my test script I send a request via sendRequest() to the url stored in pm.request.url.

When I print out pm.request.url, it shows me exactly what I expect: A url without any additional query parameters.

However, when I send the request, my postman console shows the url with some extra query parameters:

http://…?members&reference&Type&_postman_listIndexKey=key&
_postman_listAllowsMultipleValues

As far as I understood, the pm.request.url is an url object that, besides the host and path can have a list of query parameters, which I can get with the getPathWithQuery() or the getQueryString(options opt, nullable) function, both of which shall return a string. However, when I print the result of getPathWithQuery(), I get nothing but the path without the additional query parameters. The printed getQueryString() method does not even provide me anything which makes sense to me:

function(t){return this.query.count()?typeof t===OBJECT?QueryParam.unparse(this.query.all(),t):QueryParam.unparse(this.query.all(),{encode:t}):E}

When are those query parameters added to my uri and why?

Here the method I am using for sending the request:

pm.sendRequest({
url: pm.request.url,
method: 'POST',
header: {
    'content-type': 'application/json',
    'accept': '*/*',
    'connection': 'keep-alive'
    
},
body: {
    mode: 'raw',
    raw: bodyRaw
}}, function (err, res) {});

Any help is appreciated, thanks in advance :slight_smile:

Hey @NormativeSandra

Welcome to the community! :wave:

Could you post an image showing the main request URL and the test script together please?

Hi @NormativeSandra,

pm.request.url is an object. To get the URL string, you can use pm.request.url.toString(). The query params you’re seeing are likely coming from pm.sendRequest trying to parse the object into a URL string, as the params you’re getting are actually properties of the pm.request.url object.

You can try changing your code to something like this:

pm.sendRequest({
  url: pm.request.url.toString(),
  method: 'POST',
  header: {
    'content-type': 'application/json',
    'accept': '*/*',
    'connection': 'keep-alive'  
  },
  body: {
    mode: 'raw',
    raw: bodyRaw
  }}, function (err, res) {});

Hope that helps.

Best,

Kevin

1 Like

Thank you, what you said makes totally sense!

Hello, thank you for answering!

My problem has been solved but I will provide images with my next question.