The Postman JavaScript API functionality enables you to programmatically access and alter request and response data and variables using the pm object. You can also dynamically alter run order to build request workflows for the Collection Runner.
You can access and manipulate variables at each scope in Postman using the pm API.
You can use dynamic variables to generate values when your requests run.
Postman supports a variety of variable scopes. The pm object provides methods for accessing global, collection, and environment variables specifically, and pm.variables methods for accessing variables at different scopes and setting local variables.
Variable scope determines the precedence Postman gives to variables when you reference them, in order of increasing precedence:
The variable with the closest scope overrides any others. For example, if you have a score variable in both the current collection and the active environment, and you call pm.variables.get('score'), Postman returns the local value of the environment variable. When you set a variable value using pm.variables.set, the value is local and only persists for the current request or collection run.
// collection var 'score' = 1
// environment var 'score' = 2
// first request run
console.log(pm.variables.get('score')); // outputs 2
console.log(pm.collectionVariables.get('score')); // outputs 1
console.log(pm.environment.get('score')); // outputs 2
// second request run
pm.variables.set('score', 3);// local var
console.log(pm.variables.get('score')); // outputs 3
// third request run
console.log(pm.variables.get('score')); // outputs 2
See the Postman Collection SDK Variables reference for more information.
You can also access variables defined in the individual scopes with pm.environment, pm.collectionVariables, and pm.globals. You can access vault secrets in your Postman Vault with pm.vault.
Postman doesn’t support using
pm.variablesto access and manipulate vault secrets.
You can use variables in your scripts to:
Check if there is a Postman variable in the current scope:
pm.variables.has(variableName:String):function // BooleanGet the value of the Postman variable with the specified name:
pm.variables.get(variableName:String):functionPostman supports getting the value of variables without a scope.
Append a string to the value of the Postman variable using the + operator:
String + pm.variables.get(variableName:String):functionSet a local variable with the specified name and value:
pm.variables.set(variableName:String, variableValue:*):functionReturn the resolved value of a dynamic variable inside a script using the syntax {{$variableName}}:
pm.variables.replaceIn(variableName:String):function:
For example:
const stringWithVars = pm.variables.replaceIn("Hi, my name is {{$randomFirstName}}");
console.log(stringWithVars);
Return an object containing all variables with their values in the current scope. Based on the order of precedence, this will contain variables from multiple scopes.
pm.variables.toObject():function // ObjectYou need Editor access for the environment to edit environment variables.
You can use the pm.environment method in your scripts to access and manipulate variables in the active (selected) environment:
Get the name of the active environment:
pm.environment.name:StringCheck if the environment has a variable with the specified name:
pm.environment.has(variableName:String):function // BooleanGet the variable with the specified name in the active environment:
pm.environment.get(variableName:String):functionAppend a string to the value of the variable in the active environment using the + operator:
String + pm.environment.get(variableName:String):functionSet the variable with the specified name and value in the active environment:
pm.environment.set(variableName:String, variableValue:*):functionReturn the resolved value of a dynamic variable inside a script using the syntax {{$variableName}}:
pm.environment.replaceIn(variableName:String):function
For example:
//environment has vars firstName and city
const stringWithVars = pm.environment.replaceIn("Hi, my name is {{firstName}} and I live in {{city}}.");
console.log(stringWithVars);
Return all variables with their values in the active environment in a single object:
pm.environment.toObject():function // ObjectRemove a variable from the active environment, specifying the variable by name:
pm.environment.unset(variableName:String):functionClear all variables in the active environment:
pm.environment.clear():functionYou need Editor access for the collection to edit collection variables.
Use the pm.collectionVariables methods in your scripts to access and manipulate variables in the collection.
Check if there is a variable in the collection with the specified name:
pm.collectionVariables.has(variableName:String):function // BooleanReturn the value of the collection variable with the specified name:
pm.collectionVariables.get(variableName:String):functionAppend a string to the value of the collection variable using the + operator:
String + pm.collectionVariables.get(variableName:String):functionSet a collection variable with the specified name and value:
pm.collectionVariables.set(variableName:String, variableValue:*):functionReturn the resolved value of a dynamic variable inside a script using the syntax {{$variableName}}:
pm.collectionVariables.replaceIn(variableName:String):function
For example:
//collection has vars firstName and age
const stringWithVars = pm.collectionVariables.replaceIn("Hi, my name is {{firstName}} and I am {{age}}.");
console.log(stringWithVars);
Return all variables with their values in the collection in an object:
pm.collectionVariables.toObject():function // ObjectRemove the specified variable from the collection:
pm.collectionVariables.unset(variableName:String):functionClear all variables from the collection:
pm.collectionVariables.clear():functionYou need the Workspace Editor role to edit its global variables.
Use the pm.globals methods in your scripts to access and manipulate variables at the global scope within the workspace:
Check if there is a global variable with the specified name:
pm.globals.has(variableName:String):function // BooleanReturn the value of the global variable with the specified name:
pm.globals.get(variableName:String):functionAppend a string to the value of the global variable using the + operator:
String + pm.globals.get(variableName:String):functionSet a global variable with the specified name and value:
pm.globals.set(variableName:String, variableValue:*):functionReturn the resolved value of a dynamic variable inside a script using the syntax {{$variableName}}:
pm.globals.replaceIn(variableName:String):function // String
For example:
//globals include vars firstName and city
const stringWithVars = pm.globals.replaceIn("Hi, my name is {{firstName}} and I am from {{city}}.");
console.log(stringWithVars);
Return all global variables and their values in an object:
pm.globals.toObject():function // ObjectRemove the specified global variable:
pm.globals.unset(variableName:String):functionClear all global variables in the workspace:
pm.globals.clear():functionYou can use the pm.iterationData methods in your scripts to access and manipulate variables from data files during a collection run:
Check if a variable with the specified name exists in the current iteration data:
pm.iterationData.has(variableName:String):function // BooleanReturn a variable from the iteration data with the specified name:
pm.iterationData.get(variableName:String):functionAppend a string to the value of the iteration data using the + operator:
String + pm.iterationData.get(variableName:String):functionReturn the iteration data variables in an object:
pm.iterationData.toObject():function // ObjectConvert the iterationData object to JSON format:
pm.iterationData.toJSON():functionRemove the specified variable:
pm.iterationData.unset(key:String):functionUse the pm.vault methods in your scripts to access or manipulate vault secrets in your Postman Vault. Enable support for vault secrets in scripts from your Postman Vault to use the pm.vault methods. When you send a request or run a collection manually that uses the pm.vault methods, you’ll be prompted to grant or deny a collection or the workspace access to your vault secrets using scripts. To keep vault secrets in your Postman Vault secure, make sure to only run scripts you trust.
To use the methods to access your vault secrets linked to external vaults, you must use the Postman desktop app.
The pm.vault methods are supported in pre-request and post-response scripts in HTTP collections and requests. The methods are also supported in scripts when running collections manually with the Collection Runner. Scheduled collection runs, monitors, the Postman CLI, and Newman don’t support the pm.vault methods. The pm.vault methods also aren’t supported for multi-protocol requests, such as GraphQL and gRPC.
If you’re using the Postman web app to access vault secrets from scripts, use the Postman Desktop Agent. Postman recommends you use the latest version of the Postman Desktop Agent to receive recent changes and improvements.
The pm.vault methods run asynchronously in your scripts. Each method also returns a Promise object that represents the completion or failure of the method. Add the await operator before each pm.vault method to wait for the Promise and its resulting value. Note that a method without the await operator may run in your script, but it may not behave as expected. For example:
console.log(await pm.vault.get("secretKey"));
await pm.vault.set("secretKey", "newValue");
await pm.vault.unset("secretKey");
To use the pm.vault methods in scripts to access or manipulate your vault secrets, you must first enable this option from your Postman Vault.
If you try to access or manipulate vault secrets in scripts without enabling support, you’ll receive an error in the Postman Console. Also, any code that comes after a
pm.vaultmethod won’t run when you send the request.
To enable support for vault secrets in scripts, do the following:
Once you enable support for vault secrets in scripts, you can use the pm.vault methods in your HTTP collections and requests. When you send a request or run a collection manually that uses the methods, you’ll be prompted to grant or deny a collection or the workspace access your vault secrets.
When you send a request or run a collection manually that uses the pm.vault methods in scripts, you’ll be prompted to grant or deny a collection or the workspace access to your vault secrets. Postman only allows you to run these scripts from collections or workspaces you’ve granted access do to so. From your Postman Vault, you can manage the collection or workspace’s access to your vault secrets. To keep vault secrets in your Postman Vault secure, make sure to only run scripts you trust.
Make sure you’ve enabled support for vault secrets in scripts. Otherwise, you won’t be prompted to grant or deny a collection or the workspace access to your vault secrets using scripts.
If you create a new HTTP request and send the request before saving it to a collection, the request will be granted to access your vault secrets using scripts. Postman won’t prompt you to grant or deny access to your vault secrets if the request isn’t saved to a collection.
To grant or deny a collection access to your vault secrets, do the following:
Select Collections in the sidebar, then open an HTTP collection or request with a script that accesses or manipulates your vault secrets.
Select Only this collection.
Choose if you’d like to grant or deny access:
Grant Access - Select to grant all requests in the collection access to your vault secrets using scripts.
Deny Access - Select to deny all requests in the collection access to your vault secrets using scripts.
Postman won’t prompt you again for requests in the collection. From your Postman Vault, you can manage the collections you granted or denied access to your vault secrets.
To grant or deny a workspace access to your vault secrets, do the following:
Select Collections in the sidebar, then open an HTTP request with a script that accesses or manipulates your vault secrets.
Select Send to send the request.
Select Entire Workspace.
Choose if you’d like to grant or deny access:
Grant Access - Select to grant all collections and requests in the workspace access to your vault secrets using scripts.
Deny Access - Select to deny all collections and requests in the workspace access to your vault secrets using scripts.
Postman won’t prompt you again for collections or requests in the workspace. From your Postman Vault, you can manage the workspace if you granted or denied it access to your vault secrets.
To manage a collection or workspace’s access to your vault secrets, do the following:
Select
Settings in the upper right of your Postman Vault.
Select the Manage Access tab.
Select one of the following next to a collection or workspace:
If you deny the collection or workspace access to your Postman Vault, you’ll receive an error in the Postman Console when you send a request at the denied scope. Also, any code that comes after a
pm.vaultmethod won’t run when you send a request at the denied scope.
You can use the pm.vault methods in your scripts to access and manipulate your vault secrets.
Make sure you’ve enabled support for vault secrets in scripts and granted scripts in the collection or workspace access to your vault secrets using scripts. Otherwise, you’ll receive an error in the Postman Console.
To return the value of the vault secret with the specified name:
await pm.vault.get(secretKey:String):functionTo append a string to the value of the vault secret using the + operator:
String + await pm.vault.get(secretKey:String):functionTo set a vault secret with the specified name and value:
await pm.vault.set(secretKey:String, secretValue:*):functionPostman doesn’t support setting the value of vault secrets linked with external vaults.
To remove the specified vault secret:
await pm.vault.unset(secretKey:String):functionIf you log the value of a vault secret using
console.log, the value will be masked in the Postman Console by default. To unmask the value of vault secrets in the console, open your Postman Vault, selectSettings, then turn off the toggle next to Mask vault secrets from the Settings tab.
You can use pm.request, pm.response, pm.info, and pm.cookies to access request and response data in Postman. You can use pm.sendRequest to write and send requests with scripts. You can also use pm.execution.runRequest to send requests stored in your collections.
The pm.request object provides access to the data for the request the script is running within. For a Pre-request, this is the request that’s about to run. For a Post-response script, this is the request that has already run.
You can use the pm.request object pre-request scripts to alter various parts of the request configuration before it runs.
The pm.request object provides the following properties and methods:
The request URL:
pm.request.url:UrlThe list of headers for the current request:
pm.request.headers:HeaderListThe HTTP request method:
pm.request.method:StringThe data in the request body. This object is immutable and can’t be modified from scripts:
pm.request.body:RequestBodyAdd a header with the specified name and value for the current request:
pm.request.headers.add(header:Header):function
For example:
pm.request.headers.add({
key: "client-id",
value: "abcdef"
});
Delete the request header with the specified name:
pm.request.headers.remove(headerName:String):functionInsert the specified header name and value (if the header doesn’t exist, otherwise the already existing header will update to the new value):
pm.request.headers.upsert({key: headerName:String, value: headerValue:String}):function)See the Postman Collection SDK Request reference for more information.
The pm.response object provides access to the data returned in the response for the current request in scripts added to the Post-response tab. This object provides the following properties and methods:
The response status code:
pm.response.code:NumberThe status text string:
pm.response.status:Stringpm.response.headers:HeaderListThe time the response took to receive in milliseconds:
pm.response.responseTime:NumberThe size of the response received:
pm.response.responseSize:NumberThe response text:
pm.response.text():Function // StringThe response JSON, which you can use to drill down into the properties received:
pm.response.json():Function // ObjectSee the Postman Collection SDK Response reference for more information.
The pm.info object provides data related to the request and the script itself, including name, request ID, and iteration count. This object provides the following properties and methods:
The event, which will be either prerequest or test depending on where the script runs within the request:
pm.info.eventName:StringThe value of the current iteration:
pm.info.iteration:NumberThe total number of iterations that are scheduled to run:
pm.info.iterationCount:NumberThe saved name of the request running:
pm.info.requestName:StringA unique GUID that identifies the running request:
pm.info.requestId:StringThe pm.cookies object provides access to the list of cookies associated with the request. This object provides the following properties and methods:
Check whether a particular cookie (specified by name) exists for the requested domain:
pm.cookies.has(cookieName:String):Function // BooleanGet the value of the specified cookie:
pm.cookies.get(cookieName:String):Function // StringAppend a string to the value of the specified cookie using the + operator:
String + pm.cookies.get(variableName:String):functionGet a copy of all cookies and their values in an object, returning any cookies that are defined for the request domain and path:
pm.cookies.toObject():Function // ObjectSee the Postman Collection SDK Cookie List reference for more information.
You can use pm.cookies.jar to specify a domain for access to request cookies. To enable programmatic access using the pm.cookies.jar methods, first add a domain to the allowlist.
Access the cookie jar object:
pm.cookies.jar():Function // Object
For example:
const jar = pm.cookies.jar();
//cookie methods...
Set a cookie using name and value:
jar.set(URL:String, cookieName:String, cookieValue:String, callback(error, cookie)):Function // ObjectSet a cookie using PostmanCookie or a compatible object:
jar.set(URL:String, { name:String, value:String, httpOnly:Bool }, callback(error, cookie)):Function // Object
For example:
const jar = pm.cookies.jar();
jar.set("httpbin.org", "session-id", "abc123", (error, cookie) => {
if (error) {
console.error(`An error occurred: ${error}`);
} else {
console.log(`Cookie saved: ${cookie}`);
}
});
Get a cookie from the cookie jar for a particular URL:
jar.get(URL:String, cookieName:String, callback(error, value)):Function // ObjectGet all the cookies from the cookie jar for a particular URL, which are available in the callback function:
jar.getAll(URL:String, callback(error, cookies)):FunctionRemove a cookie for a particular URL:
jar.unset(URL:String, cookieName:String, callback(error)):Function // ObjectClear all cookies from the cookie jar for a particular URL:
jar.clear(URL:String, callback(error)):Function // ObjectClear and then set a cookie in sequence for a particular URL:
jar.clear(URL:String, callback(error) => {
jar.set(URL:String, cookieName:String, cookieValue:String, callback(error, cookie)):Function → Object
}):Function → Object
Function calls run asynchronously. Use a callback function to ensure functions run in sequence.
See the Postman Collection SDK Cookie reference for more information.
Use the pm.sendRequest methods to send a request asynchronously from a Pre-request or Post-response script. This enables you to run logic in the background if you are carrying out computation or sending multiple requests at the same time without waiting for each to complete. You can avoid blocking issues by adding a callback function so that your code can respond when Postman receives a response. You can then carry out any more processing you need on the response data.
To send a request in your collection using its request ID, use the
pm.execution.runRequestmethod.
You can pass the pm.sendRequest method a URL string, or can provide a complete request configuration in JSON including headers, method, body, and more.
// Example with a plain string URL
pm.sendRequest('https://postman-echo.com/get', (error, response) => {
if (error) {
console.log(error);
} else {
console.log(response);
}
});
// Example with a full-fledged request
const postRequest = {
url: 'https://postman-echo.com/post',
method: 'POST',
header: {
'Content-Type': 'application/json',
'X-Foo': 'bar'
},
body: {
mode: 'raw',
raw: JSON.stringify({ key: 'this is json' })
}
};
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
});
// Example containing a test
pm.sendRequest('https://postman-echo.com/get', (error, response) => {
if (error) {
console.log(error);
}
pm.test('response should be okay to process', () => {
pm.expect(error).to.equal(null);
pm.expect(response).to.have.property('code', 200);
pm.expect(response).to.have.property('status', 'OK');
});
});
See the Request definition and Response structure reference docs for more information.
Use the pm.execution.runRequest method in a pre-request or post-response script to send commonly used HTTP requests you’ve stored in your collections. A referenced request is the request you reference with the method. A root request is the request or collection where you call the method. The referenced and root requests can be in different workspaces, provided that you have at least Viewer permissions on the referenced request. You can call the method a maximum of 10 times from each script.
To write a request directly in your script, use the
pm.sendRequestmethod.
The method accepts the following arguments:
As its first argument, the pm.execution.runRequest method accepts the request ID of the referenced request. The request dropdown list displays when you enter the argument. Enter the request or collection’s name, then select a request from the dropdown list. The dropdown list only shows requests in the current workspace. You can also enter the request ID or link to the request. The argument displays the referenced request’s method and name, and you can click this to update the argument.
To get a request’s ID, click
Info in the right sidebar of a request and copy its ID.
As the second argument, the method accepts an options object that overrides variables referenced in the request. Learn about the order the method follows to resolve variables.
![]()
When you send the root request, the referenced request runs as it’s configured in its collection. This includes defined parameters, headers, variables, test scripts, and more. As an example, if the referenced request has test assertions in its scripts, the test results display in the root request where you called the method. As another example, if the referenced request references variables defined in one of its parent elements, these variable values are used when you send the root request.
The method runs asynchronously in your scripts and returns a Promise object that represents the completion or failure of the method. Add the await operator before the method to wait for the Promise and its resulting value. The method may run in your script without the await operator, but it may not behave as expected.
Use the syntax shown in the following example:
try {
const response = await pm.execution.runRequest(
"12345678-12345ab-1234-1ab2-1ab2-ab1234112a12",
{
variables: {
base_url: "https://example.com",
vip: "123"
}
}
);
console.log("Response received from collection request with status:", response.code, response.json());
}
catch (error) {
console.error("Failed to send a request from the collection", error);
}
Consider the following when using the pm.execution.runRequest method:
pm.execution.setNextRequest and pm.visualizer methods won’t run in the referenced request.pm.execution.skipRequest method in its pre-request script. The pm.execution.runRequest method returns null in the response.pm.vault methods and the root request is in a different collection, you’re prompted to grant the script access to your vault secrets.pm.cookies.jar, make sure the referenced request’s URL is added to the root request’s domain allowlist.pm.execution.runRequest method isn’t supported with scheduled runs, monitors, Newman, or the Postman VS Code extension.Request IDs aren’t preserved when you export a collection. If you import a collection with requests referenced using the
pm.execution.runRequestmethod, you’ll need to update the request IDs in the root request.
The pm.execution.runRequest method uses the following order, from lowest to highest priority, when resolving variables:
pm.execution.runRequest method’s second argumentFor information about Postman’s resolution precedence for variables, see Variable scopes.
The pm.execution.location property enables you to get the complete path of a request, including the folder and collection, in array format. For example, for a request named R1 in folder F1 in the C1 collection, the following post-response script code returns ["C1", "F1", "R1"]:
console.log(pm.execution.location);
// Returns the full path of a request in array format, for example:
// ["C1", "F1", "R1"]
To get the name of the current element, use the pm.execution.location.current property. For example, if you add the following code to the pre-request script of a folder named F1, it returns F1:
console.log(pm.execution.location.current);
// Returns the name of the current element, for example:
// F1
You can use the pm.execution.location and pm.execution.location.current properties in your scripts to understand which items run when a request is sent. This information enables you to implement logic and actions in your scripts tailored to the current location within your API testing or collection structure.
The pm.execution.skipRequest method enables you to stop the run of a request from a pre-request script:
pm.execution.skipRequest()
You can use the pm.execution.skipRequest method in the Pre-request tab of a request, collection, or folder. When pm.execution.skipRequest() is encountered, the request isn’t sent. Any remaining scripts in the Pre-request tab are skipped, and no tests are run. For example:
//Skip this request if an authentication token isn't present
if (!pm.environment.get('token')) {
pm.execution.skipRequest()
}
In the Collection Runner, when pm.execution.skipRequest() is encountered, Postman skips running the current request (including its post-response scripts) and moves to the next request in order. The run results will show no response and no tests found for the request. This same behavior also applies to Postman Flows, the Postman CLI, and Newman.
Using the
pm.execution.skipRequestmethod isn’t supported in the Post-response tab of a request, collection, or folder and will have no effect there. You will also get aTypeError: pm.execution.skipRequest isn't a functionConsole error.
The jsonSchema method enables you to write a test assertion that validates the response data with a JSON Schema. Postman uses version 6.12.5 of the Ajv JSON Schema validator to validate response data with a JSON Schema.
To write your test assertion, use the pm.response object and Chai Assertion Library BDD syntax to access the data returned in the response.
The jsonSchema method accepts a JSON Schema as an object in the first argument. It also accepts an object of optional Ajv options in the second argument:
pm.response.<bdd-syntax>.jsonSchema(schema, options);
You can define a JSON Schema in Postman, such as in the Scripts tab of a request. Then you can write a test that validates the properties in your response data against the defined JSON Schema.
In the following example, the JSON Schema requires the response data to contain an alpha property that’s a Boolean data type. If the response data is missing this property or it’s a different data type, the test fails. This example uses BDD syntax to.have to express the assertion:
const schema = {
"type": "object",
"properties": {
"alpha": {
"type": "boolean"
}
},
"required": ["alpha"]
};
pm.test('Response is valid', function() {
pm.response.to.have.jsonSchema(schema);
});
You can use the pm.execution.setNextRequest method for building request workflows when you use the Collection Runner or Newman.
setNextRequesthas no effect when you run requests using Send. It only has an effect when you run a collection.
When you run a collection with the Collection Runner, the Postman CLI, or Newman, Postman runs your requests in a default order or an order you specify when you set up the run. However, you can override this run order using pm.execution.setNextRequest to specify which request to run next. For example:
Run the specified request after this one (where requestName is the name of the collection’s request, for example “Get customers”):
pm.execution.setNextRequest(requestName:String):FunctionRun the specified request after this one (where requestId is the request ID returned by pm.info.requestId):
pm.execution.setNextRequest(requestId:String):Function
For example:
//script in another request calls:
//pm.environment.set('next', pm.info.requestId)
pm.execution.setNextRequest(pm.environment.get('next'));
Use pm.visualizer.set to specify a template to display response data in the Postman Visualizer:
pm.visualizer.set(layout:String, data:Object, options:Object):Function
layout required
data optional
options optional
Handlebars.compile()Example usage:
var template = `<p>{{res.info}}</p>`;
pm.visualizer.set(template, {
res: pm.response.json()
});
Use pm.getData to retrieve response data inside a Postman Visualizer template string. For example:
pm.getData(callback):FunctionThe callback function accepts two parameters:
error
data
pm.visualizer.setExample usage:
pm.getData(function (error, data) {
var value = data.res.info;
});
You can use pm.test to write test specifications inside either the Pre-request or Post-response scripts. Tests include a name and assertion:
pm.test(testName:String, specFunction:Function):Function
Postman will output test results as part of the response. The pm.test method returns the pm object, making the call chainable.
The following sample test checks that a response is valid to proceed:
pm.test("response should be okay to process", function () {
pm.response.to.not.be.error;
pm.response.to.have.jsonBody('');
pm.response.to.not.have.jsonBody('error');
});
An optional done callback can be passed to pm.test to test asynchronous functions:
pm.test('async test', function (done) {
setTimeout(() => {
pm.expect(pm.response.code).to.equal(200);
done();
}, 1500);
});
For example, to get the total number of tests run from a specific location in code:
pm.test.index():Function // NumberThe pm.expect method enables you to write assertions on your response data, using ChaiJS expect BDD syntax:
pm.expect(assertion:*):Function // AssertionYou can also use pm.response.to.have.* and pm.response.to.be.* to build your assertions.
See Postman test script examples for more assertions.
You can use the pm.require method to import packages from your team’s Postman Package Library or external package registries inside HTTP, gRPC, and GraphQL requests.
The pm.require method accepts the name of the package. Declare the method as a variable if the package has functions or objects you want to call. If the package only has code or instances of the pm object, you don’t need to declare the method as a variable:
Use the following format to import a package from the package library:
const variableName = pm.require('@team-domain/package-name');
variableName.functionName()
Use the following format to import an external package from a package registry:
// package imported from npm
const npmVariableName = pm.require('npm:package-name@version-number');
npmVariableName.functionName()
// package imported from jsr
const jsrVariableName = pm.require('jsr:package-name@version-number');
jsrVariableName.functionName()
Postman supports the following JavaScript objects globally in your scripts:
The require method enables you to use the sandbox built-in library modules. To use a library, call the require method, pass the module name as a parameter, and assign the return object from the method to a variable:
require(moduleName:String):function
The supported libraries available for use in the sandbox include:
The following libraries are deprecated and no longer supported:
- atob (use the atob method)
- btoa (use the btoa method)
- crypto-js (use the Web Crypto objects)
- tv4 (use the ajv library)
The following NodeJS modules are also available:
Postman doesn’t support the following in the buffer module: isAscii, isUtf8, resolveObjectURL, transcode, and copyBytesFrom.
You can use tests to build Postman into your development projects in a variety of ways using Postman utilities.
Last modified: 2024/09/27