Postman cheat sheet - Quick guide to automating APIs

A quick list of useful functions to use in Postman tests

Postman cheat sheet - Quick guide to automating APIs
A piece of paper with written text on it

Postman cheat sheet is something I have wanted to put together for a while as a response to helping attendees of my Testing API and Web services training. The cheat contains a high-level collection of the features available in Postman to help you to automate APIs and Web services. Unless stated otherwise the methods below are used in the Scripts tab and some can be found on the right-hand section of the tab labelled snippets.

I've organised the Postman cheat sheet based on problems users of Postman are trying to solve based on observations from previous training sessions and questions from Postman slack community. However, if there is something else you want to see added to the Postman cheat sheet, get in touch with me via Twitter @2bittester.

For more detailed information on each feature, check out

Using variables

Note: Variables are shared as strings across Postman. This means you need to ensure that whatever you want to store has to be converted to a string before storing. Failing to convert can result in behaviour such as stored parsed response bodies return as [Object object] instead of the original body. You can learn more about sharing response bodies here.



pm.globals.set("myVariable", "localhost");

Overrides variables of lower scope with the same name


pm.environment.set("myVariable", "localhost");


pm.collectionVariables.set("myVariable", "localhost");

Reading variables in request builder


For example with the variable "myVariable" set to "localhost", using http://{{myVariable}}:8080/ping will create a string of http://localhost:8080

Reading variables in test tab


let variableToUse = pm.globals.get("myVariable");

Assigns stored variable "myVariable" to the variableToUse for future use.


let variableToUse = pm.environment.get("myVariable");

Assigns stored variable "myVariable" to the variableToUse for future use.


let variableToUse = pm.collectionVariables.get("myVariable");

Assigns stored variable "myVariable" to the variableToUse for future use.




Status codes

Assert status code matches expected status code

pm.test("Status code is 200", function () {;

Assert status code name

pm.test("Status code is 200", function () {"OK");


Assert header is present

pm.test("Content-Type is present", function () {"Content-Type");

Assert header value

pm.test("Content-Type is present", function () {"Content-Type", "application/json");

Response Bodies

Assert JSON object contains a value

var jsonData = pm.response.json();

Assert XML object contains a value

var jsonObject = xml2Json(responseBody);

Assert HTML page contains a value

const $ = cheerio.load(pm.response.text());

pm.expect($('.w3col > ol > li:nth-child(1)').text()).to.equal('First item');

This uses CSS Selectors to extract required content. You can discover more on css selectors at w3schools.

Custom logging

console.log('Event I am interested in');

Conditional workflows

Set next request to run

pm.sendRequest(“Request Name”);

Exit current run


Based on information from the following Postman blog post