SDKs overview
The Postman API provides programmatic access to Postman data, allowing users to interact with collections, environments, monitors, and other Postman entities. While the Postman platform itself is a comprehensive API development environment, its API enables automation and integration with external systems. The primary official SDK for interacting with this API is the Postman Collection SDK, designed to work with the underlying structure of Postman Collections.
This SDK facilitates tasks such as creating new collections, modifying existing requests, managing environments, and executing collections programmatically. It is particularly useful for integrating Postman workflows into CI/CD pipelines, automating testing processes, or building custom tools that leverage Postman's data model. Beyond the official offering, the Postman ecosystem benefits from community-driven libraries that extend support to various programming languages, often wrapping the Postman API for simplified interaction.
Official SDKs by language
The core official SDK provided by Postman is the Postman Collection SDK, primarily developed for JavaScript and Node.js environments. This SDK is foundational for developers looking to manipulate Postman Collections and their components programmatically. It allows for advanced use cases such as dynamic generation of requests, intricate test script execution, and seamless integration with build systems.
The Postman Collection SDK is maintained by Postman and is considered the authoritative way to interact with the structural elements of Postman Collections outside of the Postman application itself. Its design aligns with the internal data model used by Postman, ensuring compatibility and access to the full range of collection features. Developers can find detailed information on its capabilities and usage in the Postman Collection SDK overview documentation.
| Language | Package/Module | Installation Command | Maturity |
|---|---|---|---|
| JavaScript/Node.js | postman-collection |
npm install postman-collection or yarn add postman-collection |
Stable, Actively Maintained |
Installation
To install the Postman Collection SDK, you will need Node.js and npm (Node Package Manager) or Yarn installed on your system. This SDK is published on the npm registry, making it accessible through standard package management commands.
Prerequisites
- Node.js (LTS version recommended)
- npm or Yarn
Node.js/npm Installation
Open your terminal or command prompt and run one of the following commands:
npm install postman-collection
or, if you prefer using Yarn:
yarn add postman-collection
This command downloads the postman-collection package and its dependencies into your project's node_modules directory, making it available for import and use in your JavaScript or TypeScript applications. For more details on Node.js package management, refer to the npm install command documentation.
Quickstart example
This example demonstrates how to use the Postman Collection SDK to programmatically load a Postman Collection, iterate through its items (requests), and access their properties. This is a common starting point for tasks like validating collection structure, generating documentation, or preparing collections for execution.
First, ensure you have the postman-collection package installed as described in the Installation section. Then, create a JavaScript file (e.g., collection-parser.js) and add the following code:
const { Collection, Item } = require('postman-collection');
// Example Postman Collection JSON structure
// In a real application, you would load this from a file or the Postman API.
const myCollectionJson = {
"info": {
"_postman_id": "b3a2c1d0-e9f8-4g7h-i6j5-k4l3m2n1o0p9",
"name": "My Sample API Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get User Details",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.example.com/users/123",
"protocol": "https",
"host": ["api", "example", "com"],
"path": ["users", "123"]
}
},
"response": []
},
{
"name": "Create New User",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"John Doe\",\n \"email\": \"[email protected]\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.example.com/users",
"protocol": "https",
"host": ["api", "example", "com"],
"path": ["users"]
}
},
"response": []
}
]
};
// Create a new Collection instance from the JSON
const myCollection = new Collection(myCollectionJson);
console.log(`Collection Name: ${myCollection.name}`);
console.log(`Collection ID: ${myCollection.id}`);
// Iterate through each item (request or folder) in the collection
myCollection.forEachItem((item) => {
if (Item.isItem(item)) { // Check if it's a request item
console.log(`\n Request Name: ${item.name}`);
console.log(` Request Method: ${item.request.method}`);
console.log(` Request URL: ${item.request.url.toString()}`);
if (item.request.body && item.request.body.raw) {
console.log(` Request Body (raw): ${item.request.body.raw.substring(0, 50)}...`);
}
}
});
To run this example, save the code as collection-parser.js and execute it using Node.js:
node collection-parser.js
This script will output the collection's name and ID, then list each request's name, HTTP method, and URL. This illustrates the basic capabilities of the Postman Collection SDK for parsing and accessing collection data structures.
Community libraries
While Postman provides a robust official SDK for working with collections, the broader developer community has created additional libraries and wrappers to simplify interaction with the Postman API across various programming languages. These community-driven efforts often aim to provide idiomatic interfaces for specific languages or to address niche use cases not directly covered by the official SDK.
Community libraries typically leverage the Postman API reference to build clients that can fetch, create, update, and delete Postman entities such as collections, environments, mocks, and monitors. They can be particularly useful for:
- Language-specific bindings: Offering a more natural coding experience for developers working in Python, Java, Go, Ruby, or other languages.
- Simplified API calls: Abstracting away direct HTTP requests and JSON parsing, providing higher-level functions.
- Integration with frameworks: Offering components or plugins that integrate Postman API capabilities into popular web frameworks or testing harnesses.
Discovering community libraries often involves searching package managers specific to each language (e.g., PyPI for Python, Maven Central for Java, RubyGems for Ruby) or exploring platforms like GitHub. Developers should exercise due diligence when selecting community libraries, considering factors such as active maintenance, community support, documentation quality, and security practices. The Postman community forum and GitHub trending repositories are good places to start looking for such contributions.