Postman Tutorial Part 32 – Retrieve Query Parameter Value in Tests Script in Postman

We have already seen usage of Query params in API. We may need to retrieve query parameters value in Tests and Pre-request Script for validation. So in this post, we will see how can we retrieve query parameters value.

To get value of specific query parameter:-

pm.request.url.query.get(<Parameter name>)

To get all query parameter as a list:-


To get query string of URI:-


Let’s see above concept in an example:-

Let’s add params to API:-

Add script to Tests:-

Hit and see Postman Console:-

Import above example from below collection:-

Refer basics of API Testing here.

Refer detailed tutorial of Postman here.

More about API Testing in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Writing technical posts and creating YouTube videos are my hobbies.

1 thought on “Postman Tutorial Part 32 – Retrieve Query Parameter Value in Tests Script in Postman

  1. Great post Amod. I was able to utilize your code examples and make this work. However, I tried running a test from the Collection Runner, that reads a .csv file that has the data, and in those instances, it’s returning just the query param variable name {{queryParam}} nor the value. Do you have a suggestion on how this may work in the instance of running a test using the Collection Runner and csv file with query parameters?

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.