Skip to content

Commit 010cac1

Browse files
committed
Created Wiki and fixed some major issues
major fixes, type definitions, and tests. Updated documentation and tests.
1 parent f66eb99 commit 010cac1

12 files changed

Lines changed: 810 additions & 16 deletions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ const newLead: Lead = await api.lead.create({
7979
- Pagination: All search/list endpoints accept `limit`/`skip` or `_limit`/`_skip` and map them to Close's `_limit`/`_skip` parameters. You can also pass `fields`/`_fields` to limit response payloads.
8080
- Email threads: The `email_thread` resource uses the documented `/activity/emailthread/` endpoints.
8181
- Rate limits: 429 retries honor `RateLimit-Reset` headers when present, otherwise fall back to `Retry-After` or the configured `retryDelay`.
82+
83+
## Wiki
84+
85+
This repo includes a small Wiki in the `Wiki/` folder with usage examples and a method-by-method resource overview.
86+
87+
- Start here: `Wiki/Home.md`

Wiki/Authentication.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Authentication
2+
3+
Close API keys use **HTTP Basic Authentication**.
4+
5+
## API base URL
6+
7+
Default base URL:
8+
9+
- `https://api.close.com/api/v1`
10+
11+
This is also the default for `closecrm-node`.
12+
13+
## How the API key is sent
14+
15+
Per the Close docs, the API key acts as the username and the password is empty. That means the Basic Auth value is base64 of:
16+
17+
- `YOUR_API_KEY:` (note the trailing colon)
18+
19+
## Using this library
20+
21+
```js
22+
const Closecom = require('closecrm-node');
23+
24+
const api = new Closecom(process.env.CLOSE_API_KEY);
25+
26+
const me = await api.user.me();
27+
```
28+
29+
## OAuth?
30+
31+
This library is primarily built around API keys. If you need to build a public app, refer to Close’s OAuth docs.
32+
33+
Reference: https://developer.close.com/topics/authentication/

Wiki/Client-Basics.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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/

Wiki/Errors-and-Rate-Limits.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Errors and Rate Limits
2+
3+
This page covers common HTTP errors, and what to do about them.
4+
5+
## Common HTTP response codes
6+
7+
Close commonly uses:
8+
9+
- `200` — success
10+
- `400` — invalid request / validation
11+
- `401` — authentication required / invalid API key
12+
- `402` — plan limit reached
13+
- `403` — operation not allowed
14+
- `404` — resource not found / endpoint not found
15+
- `405` — method not supported
16+
- `415` — unsupported format
17+
18+
Reference: https://developer.close.com/topics/http-response-codes/
19+
20+
## Rate limiting (429)
21+
22+
If you receive `429 Too Many Requests`, you should pause before retrying.
23+
24+
Close provides a `RateLimit` response header:
25+
26+
- `RateLimit: limit=100, remaining=50, reset=5`
27+
28+
…and a `Retry-After` header (in seconds).
29+
30+
This library automatically retries 429 responses up to the configured `maxRetries`.
31+
32+
Reference: https://developer.close.com/topics/rate-limits/
33+
34+
## Error messages & hints
35+
36+
This client tries to surface helpful hints for common mistakes.
37+
38+
Typical examples:
39+
40+
- 400: invalid search query / missing required fields
41+
- 401: wrong API key, missing token
42+
- 429: hit rate limit; retry after reset
43+
44+
If you need more context, log the thrown error and inspect:
45+
46+
- `error.status`
47+
- `error.message`
48+
- (sometimes) `error.body` / `error.response`

Wiki/Getting-Started.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Getting Started
2+
3+
This guide gets you from zero to your first API call.
4+
5+
## Requirements
6+
7+
- Node.js 18+ (this library uses the native `fetch()`)
8+
9+
## Install
10+
11+
```bash
12+
npm install closecrm-node
13+
```
14+
15+
## Create a client
16+
17+
```js
18+
const Closecom = require('closecrm-node');
19+
20+
const api = new Closecom(process.env.CLOSE_API_KEY);
21+
```
22+
23+
## First call: “Who am I?”
24+
25+
```js
26+
const me = await api.user.me();
27+
console.log(me);
28+
```
29+
30+
## Project structure (what you get)
31+
32+
- **CommonJS** entry (`require('closecrm-node')`)
33+
- Resources grouped by name, e.g. `api.lead`, `api.contact`, `api.activity.note`
34+
- Built-in retry behavior for **429 Too Many Requests** (rate limiting)
35+
36+
## Next
37+
38+
- [Authentication](./Authentication.md)
39+
- [Client Basics](./Client-Basics.md)
40+
- [Resources Overview](./Resources.md)

Wiki/Home.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Close.com Node.js Client – Wiki
2+
3+
Welcome to the Wiki for **`closecrm-node`** — a modern Node.js wrapper for the **Close.com REST API**.
4+
5+
This Wiki is structured so you can quickly see:
6+
7+
- which resources exist (Leads, Contacts, Activities, …)
8+
- which methods the client exposes (search/list/read/create/update/delete)
9+
- how pagination, rate limits, and error handling work
10+
11+
## Quick Links
12+
13+
- [Getting Started](./Getting-Started.md)
14+
- [Authentication](./Authentication.md)
15+
- [Client Basics (Requests, Params, Retries)](./Client-Basics.md)
16+
- [Pagination](./Pagination.md)
17+
- [Error Handling & Rate Limits](./Errors-and-Rate-Limits.md)
18+
- [Resources (Overview)](./Resources.md)
19+
20+
## The basic idea
21+
22+
Create a client once, then use the resource objects:
23+
24+
```js
25+
const Closecom = require('closecrm-node');
26+
27+
const api = new Closecom(process.env.CLOSE_API_KEY);
28+
29+
const me = await api.user.me();
30+
const leads = await api.lead.search({ query: 'company:"Acme"', limit: 100 });
31+
```
32+
33+
> Note: The official Close documentation is at https://developer.close.com

Wiki/Pagination.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Pagination
2+
3+
Close uses `_skip` and `_limit` to paginate list/search endpoints.
4+
5+
## Basic pagination
6+
7+
Example (100 per page):
8+
9+
- Page 1: `?_skip=0&_limit=100`
10+
- Page 2: `?_skip=100&_limit=100`
11+
- Page 3: `?_skip=200&_limit=100`
12+
13+
Responses usually look like:
14+
15+
```json
16+
{
17+
"data": [ /* items */ ],
18+
"has_more": true
19+
}
20+
```
21+
22+
## Using this library
23+
24+
You can use either the Close style (`_skip`, `_limit`) or the convenience aliases (`skip`, `limit`).
25+
26+
```js
27+
const res = await api.lead.search({
28+
query: 'company:"Acme"',
29+
limit: 100,
30+
skip: 0
31+
});
32+
33+
console.log(res.data.length, res.has_more);
34+
```
35+
36+
## Deep pagination notes
37+
38+
Close warns that very large `_skip` values can be inefficient or even blocked (max `_skip` varies by resource). For large exports, consider:
39+
40+
- reducing the dataset per request (e.g. using a `date_created` range)
41+
- using the Export API
42+
43+
Reference: https://developer.close.com/topics/pagination/

0 commit comments

Comments
 (0)