Documentation Index
Fetch the complete documentation index at: https://docs.affonso.io/llms.txt
Use this file to discover all available pages before exploring further.
Installation
The SDK can be installed with either npm, pnpm, bun, or yarn package managers.Requires Node.js 18+ or any runtime with native
fetch support. Zero dependencies.Quick Start
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
baseUrl | string | https://api.affonso.io/v1 | API base URL |
timeout | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 2 | Retries on 429 and 5xx errors |
fetch | function | globalThis.fetch | Custom fetch implementation |
Resources
| Resource | Methods |
|---|---|
affiliates | list, retrieve, create, update, del |
referrals | list, retrieve, create, update, del |
clicks | create |
commissions | list, retrieve, create, update, del |
coupons | list, retrieve, create, del |
payouts | list, retrieve, update |
program | Settings, payment terms, tracking, restrictions, groups, creatives, notifications, portal, fraud rules |
embedTokens | create |
marketplace | list, retrieve |
Example: Affiliates CRUD
Pagination
The SDK supports both offset and cursor-based pagination, depending on the resource.Offset Pagination
Used by affiliates, commissions, coupons, and payouts.Cursor Pagination
Used by referrals.Auto-Pagination
Both pagination types support iterating through all pages automatically:Expandable Fields
Some resources support expanding related data. Pass expand fields as comma-separated strings:Error Handling
The SDK provides typed error classes for each error type:Error Types
| Error | Status | Description |
|---|---|---|
AuthenticationError | 401 | Invalid or missing API key |
PermissionError | 403 | Insufficient permissions |
NotFoundError | 404 | Resource not found |
ValidationError | 400 | Invalid request parameters (.details[] has field-level errors) |
DuplicateError | 409 | Conflicting resource (.field indicates the conflict) |
RateLimitError | 429 | Rate limit exceeded (.retryAfter in seconds) |
InternalError | 5xx | Server error |
ConnectionError | — | Network or timeout error |
AffonsoError and include status, code, message, headers, and optional field and details.