Postman Sandbox API reference

Note: The functionality described here is exclusive to Postman's native apps for Mac, Windows, and Linux.

Global functions (pm.*)


require(moduleName:String):function → *

The require function allows you to use the sandbox built-in library modules. The list of available libraries are listed below. The list links to their corresponding documentation.

  1. atob → v2.0.3
  2. btoa → v1.1.2
  3. chai → v3.5.0
  4. cheerio → v0.22.0
  5. crypto-js → v3.1.9-1
  6. csv-parse/lib/sync → 1.2.1
  7. lodash → v4.17.4 (when used with require, the inbuilt _ object is for v3.10.1)
  8. moment → v2.18.1 (sans locales)
  9. postman-collection → v1.2.0
  10. tv4 → v1.2.7
  11. uuid → (the module loaded is a shim for original module)
  12. xml2js → 0.4.19

A number of NodeJS modules are also available:

  1. path
  2. assert
  3. buffer
  4. util
  5. url
  6. punycode
  7. querystring
  8. string_decoder
  9. stream
  10. timers
  11. events

In order to use a library, simply call the require function and pass the module name as a parameter and assign the return of the function to a variable.

var atob = require('atob'),
    _ = require('lodash'), 
arrayOfStrings =  = ['string1', 'string2'];
base64Strings =, atob); 



The pm object encloses all information pertaining to the script being executed and allows one to access a copy of the request being sent or the response received. It also allows one to get and set environment and global variables.

The object contains information pertaining to the script being executed. Useful information such as the request name, request Id, and iteration count are stored inside of this object.


    Contains information whether the script being executed is a "prerequest" or a "test" script.


    Is the value of the current iteration being run.


    Is the total number of iterations that are scheduled to run.





The pm.sendRequest function allows sending HTTP/HTTPS requests asynchronously. Simply put, with asynchronous scripts, you can now execute logic in the background if you have a heavy computational task or are sending multiple requests. Instead of waiting for a call to complete and blocking any next requests, you can designate a callback function and be notified when the underlying operation has finished.

Some things to know about pm.sendRequest():

  • The method accepts a collection SDK compliant request and a callback. The callback receives 2 arguments, an error (if any) and SDK compliant response. Refer to Collection SDK Documentation to view more information.
  • It can be used in the pre-request or the test script.
// example with a plain string URL
pm.sendRequest('', function (err, res) {
    if (err) {
    } else {
        pm.environment.set("variable_key", "new_value");
// Example with a full fledged SDK Request
const echoPostRequest = {
  url: '',
  method: 'POST',
  header: 'headername1:value1',
  body: {
    mode: 'raw',
    raw: JSON.stringify({ key: 'this is json' })
pm.sendRequest(echoPostRequest, function (err, res) {
  console.log(err ? err : res.json());
// example containing a test ** under the Tests tab only
pm.sendRequest('', function (err, res) {
  if (err) { console.log(err); }
  pm.test('response should be okay to process', function () {
    pm.expect(res)'code', 200);
    pm.expect(res)'status', 'OK');

Extended Reference:



  • pm.globals.has(variableName:String):function → Boolean
  • pm.globals.get(variableName:String):function → *
  • pm.globals.set(variableName:String, variableValue:String):function
  • pm.globals.unset(variableName:String):function
  • pm.globals.clear():function
  • pm.globals.toObject():function → Object



  • pm.environment.has(variableName:String):function → Boolean
  • pm.environment.get(variableName:String):function → *
  • pm.environment.set(variableName:String, variableValue:String):function
  • pm.environment.unset(variableName:String):function
  • pm.environment.clear():function
  • pm.environment.toObject():function → Object



In Postman, all variables conform to a specific hierarchy. All variables defined in the current iteration takes precedence over the variables defined in the current environment, which overrides ones defined in the global scope, i.e. Iteration Data < Environment < Global.

The variables defined in the individual scopes may also be accessed via pm.environment for the environment scope and pm.globals for the global scope.

  • pm.variables.get(variableName:String):function → *



The request object inside pm is a representation of the request for which this script is being run. For a pre-request script, this is the request that is about to be sent and when in a test script, this is the representation of the request that was sent.

request contains information stored in the following structure:

The following items are available in TEST SCRIPTS only.



Inside the test scripts, the pm.response object contains all information pertaining to the response that was received.

The response details are stored in the following format:

  • pm.response.code:Number
  • pm.response.reason():Function → String
  • pm.response.headers:HeaderList
  • pm.response.responseTime:Number
  • pm.response.text():Function → String
  • pm.response.json():Function → Object



The iterationData object contains data from the data file provided during a collection run.

  • pm.iterationData.get(variableName:String):function → *
  • pm.iterationData.toObject():function → Object



The cookies object contains a list of cookies that are associated with the domain to which the request was made.

  • pm.cookies.has(cookieName:String):Function → Boolean

    Check whether a particular cookie (addressed by its name) exists for the requested domain.

  • pm.cookies.get(cookieName:String):Function → String

    Get the value of a particular cookie.

  • pm.cookies.toObject:Function → Object

    Get a copy of all cookies and their values in the form of an object. The cookies returned are the ones defined for the requested domain and path.

  • pm.test(testName:String, specFunction:Function):Function

    This function is used to write test specifications inside the sandbox. Writing tests inside this function allows one to name the test accurately as well as ensure that in case of any errors inside this function, the rest of the script is not blocked.

    In the following sample test, we are checking that everything about a response is valid for us to proceed.

    pm.test("response should be okay to process", function () {;'');'error');
  • pm.expect(assertion:*):Function → Assertion

    pm.expect is a generic assertion function. Underlying this is the ChaiJS expect BDD library. Using this library, it is easy to write tests where the syntax becomes readable.

    This function is useful to deal with assertions of data from a response or variables.

    pm.test('environment to be production', function () {

Response Assertion API in test scripts

  •, optionalValue:String)
  •, optionalValue:*)*

The properties inside the object allows you to easily assert a set of pre-defined rules.


    Checks 1XX status code


    Checks 2XX status code


    Checks 3XX status code


    Checks 4XX status code


    Checks 5XX


    Checks 4XX or 5XX


    Status code must be 200


    Status code must be 202


    Status code must be 400


    Status code must be 401


    Status code 403


    Status code of response is checked to be 404


    Checks whether response status code is 429