0

I know this has already answered in How to get to request parameters in Postman?

with pm.request.url.getQueryString()

but it also returns the query parameters that's disabled (unchecked, not used)

I want the real query string that's actually sent with the requests, not all query parameters that I put on postman.

Thank you

Johnsons
  • 45
  • 8

2 Answers2

2
console.log(pm.request.toJSON().url.query.filter((x)=>x.disabled!==true))

this will give query parameters that are not disabled.

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • 1
    thanks, that filter tricks following with map (to construct key=value formatted string) and join them with ampersand simplifies my script instead of iterating query using each and storing them in new object. – Johnsons Apr 06 '21 at 12:05
0

here's what im doing rn

const queryStringList = {}
pm.request.url.query.each(param => {
    if (!param.disabled) {
        queryStringList[param.key] = param.value
    }
})
const queryString = Object.keys(queryStringList)
    .map(k => `${encodeURIComponent(k)}=${encodeURIComponent(queryStringList[k])}`)
    .join("&")

i'm basically iterating over all query parameters in dictionary form, and only picking the ones that's not disabled (unchecked) from my postman gui and rebuild it.

Johnsons
  • 45
  • 8