name, description, trigger, skip_when, sequence, related
name
description
trigger
skip_when
sequence
related
writing-api-docs
Patterns and structure for writing API reference documentation including
endpoint descriptions, request/response schemas, and error documentation.
- Documenting REST API endpoints
- Writing request/response examples
- Documenting error codes
- Creating API field descriptions
- Writing conceptual guides → use writing-functional-docs
- Reviewing documentation → use documentation-review
- Writing code → use dev-team agents
before
documentation-review
similar
complementary
writing-functional-docs
api-field-descriptions
documentation-structure
Writing API Reference Documentation
API reference documentation describes what each endpoint does, its parameters, request/response formats, and error conditions. It focuses on the "what" rather than the "why."
API Reference Principles
RESTful and Predictable
Follow standard HTTP methods and status codes
Use consistent URL patterns
Document idempotency behavior
Consistent Formats
Requests and responses use JSON
Clear typing and structures
Standard error format
Explicit Versioning
Document version in URL path
Note backward compatibility
Mark deprecated fields clearly
Endpoint Documentation Structure
Basic Structure
# Endpoint Name
Brief description of what this endpoint does.
## Request
### HTTP Method and Path
`POST /v1/organizations/{organizationId}/ledgers/{ledgerId}/accounts`### Path Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| organizationId | uuid | Yes | The unique identifier of the Organization |
| ledgerId | uuid | Yes | The unique identifier of the Ledger |
### Request Body
```json
{
"name": "string",
"assetCode": "string",
"type": "string"
}
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| name | string | Yes | The name of the Account |
| alias | string | No | A user-friendly identifier. If omitted, uses the account ID |
Deprecated Fields
| chartOfAccountsGroupName | string | **[Deprecated]** Use `route` instead. The name of the group. |
Data Types Reference
Use consistent type names across all documentation:
{"code":"ACCOUNT_NOT_FOUND","message":"The specified account does not exist","details":{"accountId":"invalid-uuid"}}
Error Table Format
Status Code
Error Code
Description
Resolution
400
INVALID_REQUEST
Request validation failed
Check request body format
401
UNAUTHORIZED
Missing or invalid authentication
Provide valid API key
403
FORBIDDEN
Insufficient permissions
Contact admin for access
404
NOT_FOUND
Resource does not exist
Verify the resource ID
409
CONFLICT
Resource already exists
Use a different identifier
422
UNPROCESSABLE_ENTITY
Business rule violation
Check business constraints
500
INTERNAL_ERROR
Server error
Retry or contact support
HTTP Status Codes
Success Codes
Code
Usage
200 OK
Successful GET, PUT, PATCH
201 Created
Successful POST that creates a resource
204 No Content
Successful DELETE
Error Codes
Code
Usage
400 Bad Request
Malformed request syntax
401 Unauthorized
Missing or invalid authentication
403 Forbidden
Valid auth but insufficient permissions
404 Not Found
Resource does not exist
409 Conflict
Resource state conflict (e.g., duplicate)
422 Unprocessable Entity
Valid syntax but invalid semantics
429 Too Many Requests
Rate limit exceeded
500 Internal Server Error
Server-side error
Pagination Documentation
When an endpoint returns paginated results:
### Query Parameters
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| limit | integer | 10 | Number of results per page (max 100) |
| page | integer | 1 | Page number to retrieve |
### Pagination Response
```json
{
"items": [...],
"page": 1,
"limit": 10,
"totalItems": 150,
"totalPages": 15
}
---
## API Versioning Notes
When documenting versioned APIs:
```markdown
> **Note:** You're viewing documentation for the **current version** (v3).
> For previous versions, use the version switcher.
For deprecated endpoints:
> **Deprecated:** This endpoint will be removed in v4. Use [/v3/accounts](link) instead.