Script Valley
Writing Technical Documentation
API Reference DocumentationLesson 3.3

Documenting API responses and error codes

response schema documentation, HTTP status codes, error response format, error code tables, pagination documentation, partial responses, null vs absent fields

Response and Error Documentation

API Response and Error Structure

Response documentation is the most-skipped section in API docs. It shouldn't be. Developers need to know exactly what they get back β€” field names, types, when fields appear, and what every error means and how to fix it.

Document Every Response Field

**Response (200 OK)**

```json
{
  "id": "string β€” UUID",
  "email": "string",
  "name": "string",
  "created_at": "string β€” ISO 8601 datetime",
  "updated_at": "string β€” ISO 8601 datetime",
  "role": "string β€” one of: admin, editor, viewer",
  "verified": "boolean β€” false until email is confirmed"
}
```

Standardize Your Error Format

**Error Response Format**

```json
{
  "error": {
    "code": "INVALID_EMAIL",
    "message": "The email address format is invalid.",
    "field": "email"
  }
}
```

Error Code Table

| Code              | HTTP Status | Cause                          | Fix                                 |
|-------------------|-------------|--------------------------------|-------------------------------------|
| INVALID_EMAIL     | 400         | Email format validation failed | Provide a valid email address       |
| USER_NOT_FOUND    | 404         | No user with given ID          | Verify the user ID exists           |
| RATE_LIMIT        | 429         | Too many requests              | Wait and retry with exponential backoff |

Document null vs absent fields explicitly. Returning null means a field exists but has no value. An absent field means different things in different APIs β€” document which you use and why.

Up next

Writing authentication and security documentation

Sign in to track progress

Documenting API responses and error codes β€” API Reference Documentation β€” Writing Technical Documentation β€” Script Valley β€” Script Valley