SDET Unicorns

Introduction to Postman Scripts

Intro to Postman Scripts

Table of Content

In this post, we will do a quick introduction to Postman Scripts. Learning scripting will give you the power to automate your API collections, so it’s really important you understand how Scripting works if you want to do API automation using Postman.

What are Postman Scripts?

Postman Scripting allows you to add dynamic behavior to requests and collections by executing JavaScript code. Essentially, what you are doing is using JavaScript code to manipulate your API requests.

There are 2 types of scripting you can do with Postman –

  • Pre-requests scripts
  • Test scripts

Pre-request Scripts – manipulate the data of the request before Postman sends the request

Test Scripts – validate the response of the request by writing tests (gets executed after Postman receives the response)

What can you do with the Scripts?

Postman Scripts allow you to change the behavior of the requests, let’s understand what that means. Using Scripts you can do some of the following:

  • Set or Get the variable values / parameters / headers / body data etc… in the request directly
  • Debugging (log output to the console)

Let’s take a look at an example –

image 3

Let’s assume you are creating a user using the POST request and then you need to fetch the id of that user in your GET request. Instead of manually copy/pasting the id, you can take advantage of scripts to do that for you.

First, you can set a variable called ‘id’ in the Tests script of the POST request. Then, get the variable in the Pre-request script of the GET request and set it in the parameter.

This allows us to automate this flow using Postman collection without having to worry about relying on existing data.

Check out the video below to learn more about Postman Scripts –

To learn about API Test Automation using JavaScript, check out my free tutorial series here –

JavaScript API Test Automation Tutorial Series

I hope this post helped you out, let me know if you have any questions in the comments below!

Happy testing! 

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster


Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

Functional vs Regression Testing

Functional Testing vs Regression Testing: Main Differences

Testing has increasingly become a requirement in the software development lifecycle in recent years. The realization that development is no longer a focal point for stakeholders but saving costs by catching defects early in their application makes it necessary to learn different testing types.

Read More »