Last updated
Importing into Postman
- Open Postman and click "Import" in the top left
- Drag and drop the generated .json file or click "Upload Files"
- The collection appears in your Collections sidebar immediately
- Import the environment file the same way, then select it from the environment dropdown
- Set your environment variable values (tokens, API keys) before running requests
- Use the Collection Runner to execute all requests in sequence and see test results
Examples
Example 1: Generated Collection Structure
A generated Postman collection JSON for a simple REST API:
{
"info": {
"name": "User Management API",
"description": "API for managing users and authentication",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Users",
"item": [
{
"name": "Get All Users",
"request": {
"method": "GET",
"url": "{{baseUrl}}/api/users",
"header": [
{ "key": "Authorization", "value": "Bearer {{accessToken}}" },
{ "key": "Content-Type", "value": "application/json" }
]
}
},
{
"name": "Create User",
"request": {
"method": "POST",
"url": "{{baseUrl}}/api/users",
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"[name]\",\n \"email\": \"[email]\"\n}"
}
}
}
]
}
]
}
Example 2: Environment Variables Configuration
Generated environment file for different deployment targets:
// Development environment (dev.postman_environment.json):
{
"name": "Development",
"values": [
{ "key": "baseUrl", "value": "http://localhost:3000" },
{ "key": "accessToken", "value": "" },
{ "key": "apiKey", "value": "dev-api-key-here" }
]
}
// Staging environment:
{
"name": "Staging",
"values": [
{ "key": "baseUrl", "value": "https://api.staging.example.com" },
{ "key": "accessToken", "value": "" },
{ "key": "apiKey", "value": "staging-api-key-here" }
]
}
// Production environment:
{
"name": "Production",
"values": [
{ "key": "baseUrl", "value": "https://api.example.com" },
{ "key": "accessToken", "value": "" },
{ "key": "apiKey", "value": "{{PROD_API_KEY}}" }
]
}
Using {{baseUrl}} instead of hardcoded URLs makes the same collection work across all environments by simply switching the active environment.
Example 3: Generated Test Scripts
Automatically generated test scripts for each endpoint:
// Tests for GET /api/users:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
pm.test("Response is an array", function () {
var jsonData = pm.response.json();
pm.expect(jsonData).to.be.an('array');
});
pm.test("Each user has required fields", function () {
var jsonData = pm.response.json();
jsonData.forEach(function(user) {
pm.expect(user).to.have.property('id');
pm.expect(user).to.have.property('name');
pm.expect(user).to.have.property('email');
});
});