</>

Technology

Postman

Difficulty

Intermediate

Interview Question

How do you debug API requests in Postman?

Answer

Debugging API Requests in Postman

Method 1: Postman Console

The Postman Console shows all network traffic, logs, and script output.

Open: View → Show Postman Console (or Ctrl + Alt + C / Cmd + Option + C)

What it shows:

  • Full request URL (with query params)
  • Request headers sent
  • Response headers received
  • Script console.log output
  • Errors and warnings

Method 2: Console.log in Scripts

JavaScript
// In Pre-request Script or Tests
console.log("Base URL:", pm.environment.get("base_url"));
console.log("Request body:", pm.request.body);
console.log("Response status:", pm.response.code);
console.log("Response body:", pm.response.json());

All output appears in the Postman Console.

Method 3: Inspect Request Details

Before sending, click the Preview button in the Request Builder to see the exact URL being constructed:

CODE
GET https://api.example.com/users?page=2&limit=10
Headers: Content-Type: application/json

Method 4: Response Inspection

After sending:

  • Body tab → Formatted JSON/XML or Raw text
  • Headers tab → All response headers
  • Cookies tab → Response cookies
  • Test Results tab → Which tests passed/failed
  • Response time → Duration in ms
  • Response size → Payload size

Method 5: pm.test Output for Debugging

JavaScript
// Use test assertions to surface debugging info
pm.test("Debug: Check response structure", function () {
    const json = pm.response.json();
    console.log("Full response:", JSON.stringify(json, null, 2));
    pm.expect(json).to.be.an("object"); // always passes, just for logging
});

Method 6: Postman Interceptor

Postman Interceptor (browser extension) captures requests from your browser and sends them to Postman for inspection and replay.

Common Debugging Scenarios

IssueHow to Debug
401 UnauthorizedCheck if token is set correctly in env variable
400 Bad RequestConsole.log the request body before sending
Empty responseCheck Content-Type header, inspect raw response
Wrong URLOpen Console to see the exact URL constructed
Script errorCheck Console for JavaScript error line numbers

Follow AutomateQA

Related Topics