Postman


๐Ÿ”ง Environments

Create two Postman environments:

Local Environment

{
  "baseUrl": "http://localhost:3000",
  "email": "your-local-email@example.com",
  "password": "yourLocalPassword"
}

Production Environment

{
  "baseUrl": "https://yourdomain.com",
  "email": "your-prod-email@example.com",
  "password": "yourProdPassword"
}

Use {{baseUrl}}, {{email}}, and {{password}} in request bodies and URLs.


๐Ÿ“‚ Collections

Create a Collection grouping all API requests (Auth, Users, Tasks, etc.).

Headers for Protected Requests

Add this to each request that requires authentication:

Key: x-access-token
Value: {{xAccessToken}}

๐Ÿ” Login Request Setup

Request

POST {{baseUrl}}/api/auth/login

Body (JSON)

{
  "email": "{{email}}",
  "password": "{{password}}"
}

Post-response Script

(Click the Post-response tab in Postman):

const xAccessToken = pm.response.headers.get("x-access-token");
pm.environment.set("xAccessToken", xAccessToken);

Postman will:

  • Store x-access-token from the login response header into the environment
  • Automatically store any cookies (e.g., lmrt) sent via Set-Cookie

  • Cookies are stored per domain (e.g., localhost, yourdomain.com)

  • Postman will automatically send them with future requests if:

    • Domains/ports match
    • Cookie jar is enabled in settings

No need to manually add cookies to the Cookie header.


๐Ÿงช Verifying

You can log cookie values in Pre-request Script or Post-response:

const cookies = pm.cookies.toObject();
console.log(cookies.lmrt);

โœ… Summary

  • Use environments to manage baseUrl, email, and password
  • Capture x-access-token in a Post-response script
  • Let Postman manage cookies automatically
  • Reference {{xAccessToken}} in protected requests
  • Use separate login credentials per environment