0% found this document useful (0 votes)
39 views2 pages

Postman Cheatsheet

The Postman JavaScript API Cheat Sheet provides a comprehensive overview of key functionalities including request and response access, variable management, test assertions, collection data handling, and utility tools. It outlines specific methods and properties for interacting with requests, responses, and environment variables. Additionally, it includes example code snippets demonstrating how to implement tests and set environment variables.

Uploaded by

ibs.analepa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Postman Cheatsheet

The Postman JavaScript API Cheat Sheet provides a comprehensive overview of key functionalities including request and response access, variable management, test assertions, collection data handling, and utility tools. It outlines specific methods and properties for interacting with requests, responses, and environment variables. Additionally, it includes example code snippets demonstrating how to implement tests and set environment variables.

Uploaded by

ibs.analepa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Postman JavaScript API Cheat Sheet

# Postman JavaScript API Cheat Sheet

## 1. Request & Response Access

- `pm.request` Current request object.


- `pm.request.headers`
- `pm.request.body`
- `pm.response` Current response object.
- `pm.response.code`
- `pm.response.status`
- `pm.response.headers`
- `pm.response.body`
- `pm.response.json()`

## 2. Variables

- `pm.variables.set(name, value)`
- `pm.variables.get(name)`
- `pm.environment.set(name, value)`
- `pm.environment.get(name)`
- `pm.environment.unset(name)`
- `pm.globals.set(name, value)`
- `pm.globals.get(name)`
- `pm.globals.unset(name)`

## 3. Tests

- `pm.test("Test name", function () { ... })`


- `pm.expect(value).to.eql(expected)`
- `pm.response.to.have.status(code)`
- `pm.response.to.be.ok`
- `pm.response.to.have.header("Content-Type")`

## 4. Collection & Iteration Data

- `pm.collectionVariables.set(name, value)`
- `pm.collectionVariables.get(name)`
- `pm.info` Meta info about request/script.
- `pm.iterationData.get("key")`
- `pm.iterationData.toObject()`

## 5. Assertions (ChaiJS)

- `pm.expect(actual).to.eql(expected)`
- `pm.expect(str).to.include("value")`
- `pm.expect(num).to.be.above(0)`

## 6. Tools

- `pm.sendRequest(options, callback)`
Postman JavaScript API Cheat Sheet

- `pm.cookies.get("cookieName")`
- `pm.cookies.jar()`

## Example

```javascript
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.environment.set("authToken", pm.response.json().token);
```

You might also like