Import packages into your scripts
You can use the pm.require method to import packages from your team’s Package Library or external package registries inside scripts in HTTP, gRPC, and GraphQL requests.
pm.require
The pm.require method accepts the name of a 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.
Examples
Use the following format to import a package from the Package Library:
Use the following format to import an external package from a package registry:
Use global objects
Postman supports the following JavaScript objects globally in your scripts:
- Standard objects
- AggregateError
- Array
- ArrayBuffer
- Atomics
- BigInt
- BigInt64Array
- BigUint64Array
- Boolean
- DataView
- Date
- Error
- EvalError
- Float32Array
- Float64Array
- Function
- Infinity property
- Int8Array
- Int16Array
- Int32Array
- Intl
- JSON
- Map
- Math
- NaN property
- Number
- Object
- Promise
- Proxy
- RangeError
- ReferenceError
- Reflect
- RegExp
- Set
- SharedArrayBuffer
- String
- Symbol
- SyntaxError
- TypeError
- Uint8Array
- Uint8ClampedArray
- Uint16Array
- Uint32Array
- URIError
- WeakMap
- WeakSet
- Document Object Model (DOM) objects
- Encoding objects
- File objects
- JavaScript objects
- HTML DOM objects
- Streams objects
- ByteLengthQueuingStrategy
- CountQueuingStrategy
- CompressionStream
- DecompressionStream
- ReadableByteStreamController
- ReadableStream
- ReadableStreamBYOBReader
- ReadableStreamBYOBRequest
- ReadableStreamDefaultController
- ReadableStreamDefaultReader
- TransformStream
- TransformStreamDefaultController
- WritableStream
- WritableStreamDefaultController
- WritableStreamDefaultWriter
- URL objects
- Web Crypto objects
Use external libraries
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:
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.