4. Collections & Folders

As your application grows, you will quickly accumulate dozens or hundreds of individual requests. Leaving them unsaved or loose in your history makes development chaotic. In Postman, the primary unit of organization is the **Collection**.

What is a Postman Collection?

A **Collection** is a group of saved API requests. It acts as a collaborative directory or folder system for your APIs. You can export collections as JSON files to share them, import them into other workspaces, or execute them sequentially in a automated test run.

Hierarchical Structure: Nested Folders

To mirror complex API structures, you can create nested folders inside a collection. This allows you to organize endpoints by feature areas, departments, or access permissions:

Acme API Collection/            <-- Main Collection
├── Authentication/              <-- Folder 1
│   ├── Login User (POST)
│   └── Logout User (POST)
├── User Profile Management/     <-- Folder 2
│   ├── Get Profile (GET)
│   └── Update Profile (PUT)
└── Payment Processing/          <-- Folder 3
    ├── Charge Card (POST)
    └── Refund Transaction (POST)

The Power of Inheritance

Instead of configuring authorization settings or writing verification scripts for every single request individually, Collections and Folders support **Inheritance**. This makes API maintenance 10x faster and prevents code duplication:

  1. Authorization Inheritance: You can define Auth settings (e.g. Bearer Token authorization) at the Collection level. Next, every request inside that collection can select "Inherit auth from parent" to apply those settings automatically. If the token changes, you only update it once at the collection root!
  2. Folder-level Pre-request Scripts: Define scripts that run BEFORE every single request in that folder. Ideal for initializing common headers or logging variables.
  3. Folder-level Tests: Define assertion scripts that execute AFTER every request in that folder. Excellent for globally verifying status codes (e.g., verifying that all responses must return in under 500ms).

Execution Order of inherited scripts

When you run a request, Postman executes Pre-Request and Test scripts in a strict hierarchical order from the top down:

PhaseExecution Sequence
Pre-RequestCollection Pre-request Script ──> Folder Pre-request Script ──> Request Pre-request Script.
API CallRequest is sent to the server ──> Response is received.
Tests AssertionsCollection Test Script ──> Folder Test Script ──> Request Test Script.
Key Benefit: If you place a test script at the Collection root level like pm.test("Status code is 200", () => pm.response.to.have.status(200)), Postman will execute that test on EVERY request inside the collection, instantly establishing global API validation!