Skip to main content

Postman

What is it?

Postman is tool to make network requests, simpllifying API development and testing. More info available at postman.com.

More information on installation and basics can be found on their site. Here are some helpful resources to get started:

Quick References Overview

Postman is filled with a lot of great features, but here's just a quick reference guide into some of the features often used but hardly remembered.

Working with variables

Variables can be set from the environment tab, but sometimes you want to do something more dynamic, like setting an access token as a global variable to use in a future request. Examples on use cases below

Reading a response JSON body and setting a value to a global variable

pm.globals.set('your_global_variable_name', pm.response.json()['json_key_name'])

Reading a response JSON body and setting as an environment variable

var data = pm.response.json()['your_data']
pm.environment.set('your_environment_variable_name', JSON.stringify(data));

Accessing a variable in a script (ex: pre-request, test)

pm.environment.get("your_environment_variable_name")

Reading response headers

pm.response.headers.get('Location');

Working with Tests

Basic Syntax

pm.test("Something should do something expected description", function () {
// your tests
});

Expecting a response to include a string

pm.expect(pm.response.text()).to.include("hello world");

Expect a response to equal (or not equal) something

// Expect it to equal
pm.expect(respones_value).to.equal(expected_response_value);

// Expect it to not equal
pm.expect(respones_value).not.to.equal(unexpected_response_value)

Expect a specific response status code

pm.response.to.have.status(302);