|
| 1 | +# Client Basics |
| 2 | + |
| 3 | +This page explains how requests are made, how to pass query parameters, and how retries work. |
| 4 | + |
| 5 | +## Constructor |
| 6 | + |
| 7 | +```js |
| 8 | +const Closecom = require('closecrm-node'); |
| 9 | + |
| 10 | +const api = new Closecom('your-api-key', { |
| 11 | + baseUrl: 'https://api.close.com/api/v1', // optional |
| 12 | + maxRetries: 3, // optional |
| 13 | + retryDelay: 1000 // optional (ms) |
| 14 | +}); |
| 15 | +``` |
| 16 | + |
| 17 | +### Options |
| 18 | + |
| 19 | +- `baseUrl`: Override Close API base URL (rarely needed) |
| 20 | +- `maxRetries`: How often to retry on rate limiting (HTTP 429) |
| 21 | +- `retryDelay`: Fallback delay (ms) if the server doesn’t provide a usable header |
| 22 | + |
| 23 | +## Passing query params |
| 24 | + |
| 25 | +Most “list/search” methods accept pagination and field selection parameters. |
| 26 | + |
| 27 | +Supported aliases: |
| 28 | + |
| 29 | +- `limit` or `_limit` |
| 30 | +- `skip` or `_skip` |
| 31 | +- `fields` or `_fields` |
| 32 | + |
| 33 | +Example: |
| 34 | + |
| 35 | +```js |
| 36 | +const leads = await api.lead.search({ |
| 37 | + query: 'status:"Potential"', |
| 38 | + limit: 100, |
| 39 | + skip: 0, |
| 40 | + fields: 'id,name,status_label' |
| 41 | +}); |
| 42 | +``` |
| 43 | + |
| 44 | +## Typical method patterns |
| 45 | + |
| 46 | +Most resources follow the same pattern: |
| 47 | + |
| 48 | +- `search(options)` for collections |
| 49 | +- `create(data)` |
| 50 | +- `read(id)` |
| 51 | +- `update(id, data)` |
| 52 | +- `delete(id)` |
| 53 | + |
| 54 | +Some resources use `list(options)` instead of `search(options)`. |
| 55 | + |
| 56 | +## Retries / rate limiting |
| 57 | + |
| 58 | +If Close responds with **429 Too Many Requests**, the client retries automatically up to `maxRetries`. |
| 59 | + |
| 60 | +Close provides rate limit hints via headers (see Close docs): |
| 61 | + |
| 62 | +- `RateLimit: limit=..., remaining=..., reset=...` |
| 63 | +- `Retry-After: <seconds>` |
| 64 | + |
| 65 | +Reference: https://developer.close.com/topics/rate-limits/ |
0 commit comments