hubspot-cli 0.2.0

LLM-native command-line interface for HubSpot CRM API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<div align="center">

# hubspot-cli

### Your AI Agent's Gateway to HubSpot CRM

*The command-line interface designed for LLMs, automation pipelines, and developers who think in JSON.*

[![Crates.io](https://img.shields.io/crates/v/hubspot-cli?style=for-the-badge&logo=rust&logoColor=white&color=orange)](https://crates.io/crates/hubspot-cli)
[![Downloads](https://img.shields.io/crates/d/hubspot-cli?style=for-the-badge&color=green)](https://crates.io/crates/hubspot-cli)
[![CI](https://img.shields.io/github/actions/workflow/status/dipankar/hubspot-cli/ci.yml?branch=main&style=for-the-badge&logo=github&label=CI)](https://github.com/dipankar/hubspot-cli/actions)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue?style=for-the-badge)](LICENSE)

---

**[Quick Start](#-quick-start)** · **[For AI Agents](#-designed-for-ai-agents)** · **[Examples](#-usage-examples)** · **[API Reference](#architecture)**

</div>

## The Problem

Traditional CLIs are built for humans. They output pretty tables, colorful text, and interactive prompts. That's great for manual use—but **terrible for AI agents and automation**.

When Claude, GPT, or your automation scripts interact with a CLI, they need:
- **Predictable JSON output** — not tables that break when columns change
- **Machine-readable error codes** — not "Something went wrong"
- **Discoverable APIs** — the ability to explore what's possible
- **Consistent behavior** — same input, same output, every time

**hubspot-cli** is built from the ground up for this world.

---

## ✨ Key Features

<table>
<tr>
<td width="50%">

### 🤖 AI-Native Design
```json
{
  "success": true,
  "data": { ... },
  "paging": { "next_cursor": "abc" }
}
```
Every command returns structured JSON. Errors include codes like `RATE_LIMIT_EXCEEDED` with actionable suggestions. No parsing HTML or guessing formats.

</td>
<td width="50%">

### ⚡ Blazing Fast
- **Native Rust** — 10ms startup, minimal memory
- **Smart caching** — metadata cached 1hr, objects 5min
- **Rate limit aware** — never hit HubSpot's limits
- **Auto-retry** — exponential backoff built-in

</td>
</tr>
<tr>
<td width="50%">

### 📦 Complete CRM Coverage
- Contacts, Companies, Deals, Tickets
- Products, Quotes, Line Items
- Custom Objects with schema discovery
- Associations & Pipelines
- Batch operations (up to 100 at once)

</td>
<td width="50%">

### 🔧 Production Ready
- **Multi-account** — named profiles for different portals
- **Secure** — tokens never logged, account-isolated cache
- **Scriptable** — consistent exit codes (0-10)
- **Flexible output** — JSON, pretty JSON, table, CSV

</td>
</tr>
</table>

---

## 🚀 Quick Start

### Install

```bash
# From crates.io
cargo install hubspot-cli

# Or download pre-built binary from GitHub Releases
# https://github.com/dipankar/hubspot-cli/releases
```

### Configure

```bash
export HUBSPOT_ACCESS_TOKEN="pat-na1-xxxxxxxx"
```

Get your token: [HubSpot Private Apps](https://app.hubspot.com/private-apps/)

### Use

```bash
# Check authentication
hubspot auth status

# List contacts (returns JSON)
hubspot crm contacts list --limit 5

# Create a contact
hubspot crm contacts create --email "jane@acme.com" --firstname "Jane"

# Search deals over $50k
hubspot crm deals search --filter-groups '[{"filters":[{"propertyName":"amount","operator":"GTE","value":"50000"}]}]'

# Explore available properties
hubspot discover properties contacts
```

---

## 🤖 Designed for AI Agents

### Structured Output — Always

Every command returns consistent JSON:

```bash
$ hubspot crm contacts get 12345
```
```json
{
  "success": true,
  "data": {
    "id": "12345",
    "properties": {
      "email": "jane@example.com",
      "firstname": "Jane",
      "lastname": "Doe",
      "lifecyclestage": "customer"
    },
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-16T14:22:00Z"
  }
}
```

### Errors That Help

When things go wrong, you get actionable information:

```json
{
  "success": false,
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "API rate limit exceeded",
    "category": "rate_limit",
    "suggestions": [
      "Wait 60 seconds before retrying",
      "Use batch operations to reduce API calls"
    ],
    "retry": {
      "retryable": true,
      "retry_after_seconds": 60
    }
  }
}
```

### Self-Documenting API

Agents can discover capabilities at runtime:

```bash
# What CRM objects exist?
hubspot discover objects

# What properties can I use for contacts?
hubspot discover properties contacts

# What are the deal pipeline stages?
hubspot crm pipelines list deals
```

### Exit Codes for Automation

| Code | Meaning | Action |
|------|---------|--------|
| `0` | Success | Continue |
| `3` | Auth failed | Check token |
| `5` | Validation error | Fix input |
| `6` | Not found | Check ID |
| `7` | Rate limited | Wait & retry |
| `8` | Server error | Retry later |

---

## 🐍 Integration Examples

### Python Agent

```python
import subprocess
import json

def hubspot(cmd: str) -> dict:
    """Execute hubspot-cli command and return parsed JSON."""
    result = subprocess.run(
        f"hubspot {cmd}",
        shell=True,
        capture_output=True,
        text=True
    )
    return json.loads(result.stdout)

# Discover available properties
props = hubspot("discover properties contacts")
print(f"Found {len(props['data'])} contact properties")

# List recent contacts
contacts = hubspot("crm contacts list --limit 10 -P email,firstname,lifecyclestage")
if contacts["success"]:
    for c in contacts["data"]:
        print(f"{c['properties']['email']} - {c['properties'].get('lifecyclestage', 'unknown')}")

# Create a contact
new_contact = hubspot('crm contacts create --email "lead@example.com" --firstname "New Lead"')
print(f"Created contact: {new_contact['data']['id']}")
```

### Shell Script

```bash
#!/bin/bash
set -e

# Export contacts to CSV
hubspot crm contacts list --limit 1000 --output csv > contacts.csv

# Create contacts from JSON file
while IFS= read -r line; do
    email=$(echo "$line" | jq -r '.email')
    name=$(echo "$line" | jq -r '.name')
    hubspot crm contacts create --email "$email" --firstname "$name"
done < leads.json

# Check for rate limiting
result=$(hubspot discover rate-limits)
remaining=$(echo "$result" | jq '.data.daily_remaining')
echo "API calls remaining today: $remaining"
```

### Claude/LLM Tool Definition

```json
{
  "name": "hubspot_crm",
  "description": "Interact with HubSpot CRM via CLI",
  "parameters": {
    "command": {
      "type": "string",
      "description": "The hubspot-cli command to execute",
      "examples": [
        "crm contacts list --limit 10",
        "crm deals search --filter-groups '[{\"filters\":[{\"propertyName\":\"amount\",\"operator\":\"GTE\",\"value\":\"10000\"}]}]'",
        "discover properties contacts"
      ]
    }
  }
}
```

---

## 📖 Usage Examples

### Contact Operations

```bash
# List with specific properties
hubspot crm contacts list --limit 100 -P email,firstname,company,lifecyclestage

# Get single contact
hubspot crm contacts get 12345 -P email,phone,company

# Create with all details
hubspot crm contacts create \
  --email "jane@acme.com" \
  --firstname "Jane" \
  --lastname "Doe" \
  --phone "+1-555-123-4567" \
  --company "Acme Inc"

# Update existing
hubspot crm contacts update 12345 --properties '{"lifecyclestage":"customer"}'

# Search by email domain
hubspot crm contacts search --query "email:*@acme.com"

# Batch create (up to 100)
hubspot crm contacts batch-create --inputs '[
  {"properties":{"email":"a@example.com","firstname":"Alice"}},
  {"properties":{"email":"b@example.com","firstname":"Bob"}}
]'
```

### Deal Operations

```bash
# List deals in pipeline
hubspot crm deals list --limit 50 -P dealname,amount,dealstage

# Create deal
hubspot crm deals create \
  --dealname "Enterprise Contract" \
  --amount "150000" \
  --pipeline "default" \
  --stage "qualifiedtobuy"

# Search high-value deals
hubspot crm deals search --filter-groups '[{
  "filters": [
    {"propertyName": "amount", "operator": "GTE", "value": "100000"},
    {"propertyName": "dealstage", "operator": "NEQ", "value": "closedlost"}
  ]
}]'
```

### Company & Ticket Operations

```bash
# Create company
hubspot crm companies create \
  --name "Acme Corporation" \
  --domain "acme.com" \
  --industry "Technology"

# Create support ticket
hubspot crm tickets create \
  --subject "Integration Issue" \
  --content "Customer reporting API timeout errors" \
  --priority "HIGH"

# List tickets by priority
hubspot crm tickets search --filter-groups '[{
  "filters": [{"propertyName": "hs_ticket_priority", "operator": "EQ", "value": "HIGH"}]
}]'
```

### Discovery & Debugging

```bash
# List all CRM object types
hubspot discover objects

# Get contact properties (custom only)
hubspot discover properties contacts --custom-only

# Check rate limit status
hubspot discover rate-limits

# Preview command without executing
hubspot crm contacts create --email "test@test.com" --dry-run
```

---

## ⚙️ Configuration

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `HUBSPOT_ACCESS_TOKEN` | HubSpot private app token | *required* |
| `HUBSPOT_PROFILE` | Active profile name | `default` |
| `HUBSPOT_OUTPUT_FORMAT` | Output format (`json`, `table`, `csv`) | `json` |
| `HUBSPOT_NO_CACHE` | Disable caching | `false` |

### Config File

Location: `~/.config/hubspot-cli/config.toml`

```toml
default_profile = "default"

[output]
format = "json"

[api]
base_url = "https://api.hubapi.com"
timeout_seconds = 30
max_retries = 3

[cache]
enabled = true
metadata_ttl_seconds = 3600   # Properties, schemas: 1 hour
objects_ttl_seconds = 300     # Contacts, deals: 5 minutes

[profiles.default]
access_token_env = "HUBSPOT_ACCESS_TOKEN"

[profiles.production]
access_token_env = "HUBSPOT_PROD_TOKEN"
portal_id = "123456"

[profiles.sandbox]
access_token_env = "HUBSPOT_SANDBOX_TOKEN"
```

### Global Options

| Option | Short | Description |
|--------|-------|-------------|
| `--output` | `-o` | Format: `json`, `json-pretty`, `table`, `csv` |
| `--profile` | `-p` | Use specific auth profile |
| `--quiet` | `-q` | Suppress non-essential output |
| `--verbose` | `-v` | Enable debug output |
| `--no-cache` | | Bypass cache for this request |
| `--dry-run` | | Preview without executing |

---

## Architecture

```
hubspot <domain> <object> <action> [options]
   │        │        │        │
   │        │        │        └── list, get, create, update, delete, search
   │        │        └── contacts, companies, deals, tickets, products, quotes...
   │        └── crm, auth, discover, config
   └── CLI binary

# Examples:
hubspot crm contacts list --limit 10
hubspot crm deals create --dealname "Big Deal" --amount 50000
hubspot discover properties contacts
hubspot auth status
```

---

## Development

```bash
# Clone and build
git clone https://github.com/dipankar/hubspot-cli
cd hubspot-cli
cargo build --release

# Run tests (122 tests)
cargo test

# Format and lint
cargo fmt && cargo clippy

# Install locally
cargo install --path .
```

---

## Contributing

Contributions welcome! Please:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Write tests for new functionality
4. Ensure `cargo test` and `cargo clippy` pass
5. Submit a Pull Request

---

## License

MIT — see [LICENSE](LICENSE) for details.

---

<div align="center">

**Built for the AI-first era of software development.**

[GitHub](https://github.com/dipankar/hubspot-cli) · [Crates.io](https://crates.io/crates/hubspot-cli) · [HubSpot API Docs](https://developers.hubspot.com/docs/api/overview)

</div>