Newman does not connect to your Postman account. It reads JSON files. You need to export your collection and environment from Postman into .json files on disk. Think of it like saving a Word document as PDF — same content, portable format.
Open Postman. Go to Collections in the left sidebar.
Right-click on your collection (or click the three dots ...).
Select "Export" from the dropdown menu.
Choose "Collection v2.1" format — this is what Newman expects.
Save the file. Name it something sensible: my-api-tests.postman_collection.json.
Place it in your project folder, e.g., /collections/ directory.
Click the "Environments" tab in the left sidebar.
Click the three dots (...) next to your environment name.
Select "Export."
Save as: staging.postman_environment.json (or dev, prod, etc.).
Place it in your project folder, e.g., /environments/ directory.
A clean project folder structure looks like this:
api-tests/
├── collections/
│ └── my-api-tests.postman_collection.json
├── environments/
│ ├── dev.postman_environment.json
│ ├── staging.postman_environment.json
│ └── prod.postman_environment.json
├── data/
│ ├── users-test-data.csv
│ └── orders-test-data.json
├── reports/ # Newman writes reports here
├── package.json
└── .gitignoreWhen you export an environment, only Initial Values are included. Current Values (where you put secrets) are NOT exported. This is by design — you do not want API keys in git. For CI/CD, pass secrets via the --env-var flag or CI environment variables.
You do not need to edit these files by hand. But it helps to know the structure. The collection JSON contains all your requests, tests, pre-request scripts, and collection variables.
{
"info": {
"name": "My API Tests",
"_postman_id": "abc-123-xyz",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get All Users",
"request": {
"method": "GET",
"url": "{{baseUrl}}/users"
},
"event": [
{
"listen": "test",
"script": {
"exec": ["pm.test('Status 200', function() { pm.response.to.have.status(200); });"]
}
}
]
}
]
}Add *.postman_environment.json to your .gitignore — especially production environments. Collections are safe to commit (they contain test logic, not secrets). But always review before committing to make sure no one hardcoded a password.
Q: How do you export Postman collections for use with Newman?
A: Right-click the collection in Postman, select Export, choose Collection v2.1 format, and save as a JSON file. For environments, go to the Environments tab, click the three dots, and export. Important: only Initial Values are exported, not Current Values — this prevents secrets from leaking. In CI/CD, you pass secrets via newman run collection.json --env-var "apiKey=$API_KEY" using CI environment variables. Keep collections in a /collections/ folder and environments in /environments/ within your project.
Key Point: Export collections as v2.1 JSON. Export environments separately. Only Initial Values are included — pass secrets via --env-var in CI.