Parameterize Values in Postman

Hirosh Tharaka
Techie QA
Published in
4 min readNov 21, 2017

--

Recently created a postman collection for some of the business flows in a mobile application from API level, after intercepting the calls in-between the secured endpoint and the mobile app as described in a previous post.

While creating the request collection manually for various business flows by duplicating some steps, data passing became a time consuming extra work during an execution where each request was to send separately after copying a token or an Id from the previous response to the next request.

Following the manual process of ‘CTRL + C’ and ‘CTRL + V’ for several times made my self dig into and explore an alternative, lazy solution or an approach due to the time and effort that had to invest on after each request is sent to the endpoint.

Even though its not a great discovery for a certain extent; after figuring out the solution to overcome the copy and paste procedure during the execution the idea of documenting the solution to assist another came up to my mind.

Therefore this guide will be useful for anyone who is stepping into Postman or into Scripting with Postman, and to get a thing done easily. For any script-writer with the exposure in JavaScript, this article will be a piece of cake without any doubt apart from the Postman configuration and usage.

For the purpose to explaining the solution, the extraction of an access-token from an authenticated response will be considered through-out this article as “the example”.

  1. Verification

Initially, before setting up the surrounding make sure to send a request to the endpoint with related headers and body to verify the endpoint, identify the nature of the response and identify the elements needed to be capture.

According to the screen shot above, the required headers and body information have been sent to the Sign-In endpoint to receive the HTTP status code of 200 OK along with the access_token, token_type, refresh_token, expires in, scope elements in the response body.

2. Setup

After ensuring the response of the endpoint and identifying the elements that needs to be capture for the parameters during the execution, setup a new environment under Manage Environment in Postman.

There after; define the keys(parameters) with empty values under the newly created environment as the elements needed to capture are already decided.

According to the example, access_token and refresh_token are defined as parameters to capture the values during the runtime.

3. Script

Capturing is where the knowledge of scripting is needed to write down a code snippet for the extraction of each element from the response body. The ‘tests’ tab is given by the Postman to write down customized scripts.

According the code-snippet below, script is written to take the response initially to a var. Afterwards to extract the access_token and the refresh_token from the response body and store in the environment variable aka the keys created under the newly created environment.

4. Hit

After completing the scripting, click upon the ‘Send’ to hit the request on the endpoint.

Hit the Endpoint by Clicking upon the Send button

5. Capture & Parameterize

Verify the functionality of the written script by opening the ‘Environment Quick Look’ pop-up. If the values shown in the response body are identical to the values of the keys created during the Setup, the Element Extraction and Parameterizing is successful.

According to the screen shot above, the values of the access_token and the refresh_token are captured as expected in the example and stored in the created environment variables (keys)

Yes! Element extraction and Parameterizing is Successful. But, What is the purpose of parameterizing the values if we are not aware of the way to reuse the captured values from the parameters/keys/variables to another request header, body or endpoint URL?

6. Reuse

Identify the next request in sequence which needs to carry the captured element value. Build the particular request and verify the availability of the new endpoint by copy and pasting the key-value for the verification purpose of the endpoint.

If the endpoint returns a success or a 200 OK as the HTTP response, proceed to parameterize the values in the request header, body or endpoint with the keys defined in the environment by using the key in-between double curly braces {{}}.

Ex: {{access_token}}, {{refresh_token}}

According the image above, the value of the key ‘access_token’ has been used to pass to the authorization header along with a define prefix (Bearer).

Feel free to leave your feedback and comments, which can lead us for a friendly discussion below.

Applause and Leave Feedback

--

--

Hirosh Tharaka
Techie QA

BSc(Hons), CSM®, ISTQB® (CTFL, CTAL-TTA, CTAL-TM) | Technical Writer | Technical Tester (QA Lead)