Skip to content

th-1b445c: paginate th api crm {contacts,companies,deals} list#188

Open
brentrager wants to merge 1 commit into
mainfrom
crm-list-pagination
Open

th-1b445c: paginate th api crm {contacts,companies,deals} list#188
brentrager wants to merge 1 commit into
mainfrom
crm-list-pagination

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

th api crm contacts|companies|deals list only sent ?limit= (default 50; the API clamps to a 200-row max page) with no --offset and no auto-paginate, so they silently returned only the first page. Real example: contacts list --limit 1000 returned 200 rows while the endpoint's x-total-count header said 267 — 67 contacts silently dropped. The API endpoint was always fine (it supports limit+offset and returns x-total-count); the bug was CLI-only.

Fix

Each list command gains two flags:

  • --offset <N> — page past the first page (default 0).
  • --all — fetch every page, ignoring --limit/--offset.

--all reuses the offset-paginating loop that the import scan already used. That loop is generalized into a single fetch_all_resource(client, org, resource, search, rate) helper (loops GET /organizations/{org}/crm/{resource}?limit=200&offset={offset} until a short page, url-encoding &search= when present). The existing fetch_all now delegates to it — import behavior is unchanged, including its rate pacing so the existing-contacts scan stays under the 100-req/60s limit.

Notes:

  • Non---all list now appends &offset={offset} to the single-page request; existing search/stage/json behavior is preserved.
  • For companies/deals (which render a table/pipeline by default), --all prints the aggregated JSON array rather than trying to render the full pull.
  • The deals --stage filter is not applied in --all mode — the endpoint filters by stage, not the shared paginator's search. This is documented in the flag help.

Verification

  • cargo build -p smooai-smooth-cli — passes (exit 0).
  • cargo clippy -p smooai-smooth-cli — 0 errors, no new lints in crm.rs.
  • cargo fmt -p smooai-smooth-cli — applied.
  • th api crm contacts list --help now shows:
    --offset <OFFSET>  Skip the first N contacts (page offset) [default: 0]
    --all              Fetch every page (ignores --limit/--offset)
    
    Same --offset/--all present on companies list and deals list.

Changeset: @smooai/smooth (minor).

🤖 Generated with Claude Code

These list commands only sent `?limit=` (default 50; the API clamps to a
200-row max page) with no offset and no auto-paginate, so they silently
returned just the first page — `contacts list --limit 1000` came back with
200 rows while the endpoint's x-total-count said 267, dropping 67 contacts
with no warning. The endpoint was always fine; the CLI was the bug.

Each `list` now takes `--offset <N>` and `--all` (fetch every page). `--all`
reuses the offset-paginating loop the import scan already used, generalized
into `fetch_all_resource` and paced to stay under the 100-req/60s limit;
`fetch_all` now delegates to it so import behavior is unchanged. The deals
`--stage` filter is not applied in `--all` mode (the endpoint filters by
`stage`, not the paginator's `search`).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NckP97y2ADKRwq5kkRSdPz
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: af20787

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/smooth Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager brentrager enabled auto-merge (squash) July 11, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant