Prompt
How do I diagnose API test failures with request and response logs?
Latest observation
Oct 6, 2026
OpenAI APIWeb search: off
To diagnose API test failures using request and response logs, focus on what was sent, what came back, and how that differs from expectations.
1) Capture the full request
Log:
- HTTP method
- Full URL/path
- Query parameters
- Headers
- Body/payload
- Auth details used
- Correlation/request ID if available
Example:
POST /v1/orders?dryRun=true
Headers: Authorization=Bearer xxx, Content-Type=application/json
Body: {"itemId":"123","qty":2}
2) Capture the full response
Log:
- Status code
- Headers
- Body
- Response time
- Any server-generated request ID
Example:
HTTP 400
Headers: Content-Type=application/json, X-Request-Id=abc-123
Body: {"error":"qty must be greater than 0"}
3) Compare actual vs expected
Check:
- Status code mismatch: expected
200, got400/401/500 - Payload mismatch: missing/extra fields, wrong types, wrong values
- Schema mismatch: invalid JSON shape or formatting
- Header mismatch: content type, auth, encoding
- Timing issues: timeout, slow response, retries
- Environment mismatch: wrong base URL, test data, feature flags
4) Look for common failure patterns
- 401/403: auth token expired, wrong permissions
- 400: invalid request payload, missing required fields
- 404: wrong endpoint, wrong path parameters
- 409: duplicate or conflicting data
- 422: validation failed
- 500: server-side bug or bad downstream dependency
- Timeouts: network issue, slow backend, incorrect test timeout
5) Correlate with server logs
If possible, use:
- Request ID / correlation ID
- Timestamp
- User/test case ID
Match the client-side log entry to the server-side trace to see whether:
- the request reached the server,
- validation failed early,
- a downstream call failed,
- the response was generated incorrectly.
6) Redact sensitive data
Before sharing logs:
- mask tokens, passwords, API keys
- hide personal data
- keep enough structure to debug
7) Use a checklist for each failure
For each failed test, answer:
- Did the request go to the correct endpoint?
- Was the method correct?
- Were headers/auth correct?
- Was the body valid JSON and complete?
- Did the response status match expectations?
- Did the response body match the schema?
- Is the failure reproducible?
- Do server logs confirm the same error?
8) Add structured logging if you can
Prefer logs like:
{
"testName": "create-order",
"method": "POST",
"url": "/v1/orders",
"requestId": "abc-123",
"status": 400,
"durationMs": 182,
"error": "qty must be greater than 0"
}
This makes filtering and comparison much easier.
If you want, I can also give you:
- a step-by-step debugging workflow,
- a sample log format,
- or a Python/JavaScript example for capturing request/response logs in tests.