Skip to content
Back to skills

Xaffinity Cli Usage

ASecurity

Runs the xaffinity CLI in bash to read and manage Affinity CRM data: look up companies and people, see which lists/pipelines a company is on and its list field values (Status, Owner), export lists to JSON/CSV, filter pipelines, dedup-check before adding to a list, read field change history (who changed what, deltas since a date), org-wide email/meeting/note feeds, meeting transcripts, team relationships and merge history, manage dropdown options, and create notes, interactions and list entrie...

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 12, 2026
developmentpythongoshellbashgitapi

Works with

  • cli
  • api
  • mcp

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 7 files and shows the line behind each finding

Scanned November 12, 2026

npx -y skills add yaniv-golan/affinity-sdk --skill xaffinity-cli-usage --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Xaffinity Cli Usage?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Xaffinity Cli Usage
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/yaniv-golan-xaffinity-cli-usage/badge)](https://www.skillsdirectory.com/skills/yaniv-golan-xaffinity-cli-usage)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: xaffinity-cli-usage
description: >
  Runs the xaffinity CLI in bash to read and manage Affinity CRM data: look up companies and
  people, see which lists/pipelines a company is on and its list field values (Status, Owner),
  export lists to JSON/CSV, filter pipelines, dedup-check before adding to a list, read field
  change history (who changed what, deltas since a date), org-wide email/meeting/note feeds,
  meeting transcripts, team relationships and merge history, manage dropdown options, and create
  notes, interactions and list entries. Use when the user mentions xaffinity, asks for Affinity
  CLI commands, bash scripts, flags or CSV exports, or needs Affinity CRM data and no Affinity
  MCP tools are available. Not for pipeline-history analysis (pipeline-history skill) or
  structured MCP queries (query-language skill) when those skills are available.
---

# xaffinity CLI Usage

## REQUIRED FIRST STEP: Verify API Key

Before anything else, run:

```bash
xaffinity config check-key --json
```

- **`command not found`** (exit 127; e.g. a Claude Cowork VM) — install it once per task:
  `pip install --user -q --no-warn-script-location "affinity-sdk[cli]==2.0.8"` (about 10s), then
  start every later bash call with `export PATH="$HOME/.local/bin:$PATH";` (each call is a
  fresh shell) and run check-key again. Details and the no-network case: `references/setup.md` (Claude Cowork).
- **`"configured": true`** — use the `pattern` field from the output for ALL subsequent commands:
  copy its flags (`--dotenv`, and `--env-file <path>` when it names one) into every command.
- **`"configured": false`** — stop and help the user set up. Read `references/setup.md` (key
  resolution order, `xaffinity config setup-key` — interactive, the user must run it — and the
  Cowork key-in-a-connected-folder setup, which needs `--env-file` with the folder's path).

## Read JSON from the right key

`--json` emits **one** JSON object (not NDJSON): `{"ok", "data", "warnings", "meta", ...}`. The
shape of `data` differs by command — reading the wrong key gives `null`, which looks like real
"empty" data. Use this table:

| Command | Read |
|---------|------|
| `list export` | `.data.rows[]` — `listEntryId`, `entityId`, `entityName`, + field values by name |
| `person ls` / `company ls` | `.data.persons[]` / `.data.companies[]` |
| `person get` / `company get` / `opportunity get` | `.data.person` / `.data.company` / `.data.opportunity` |
| …with `--expand list-entries` / `lists` / `persons` | `.data.listEntries` / `.data.lists` / `.data.persons` — **next to** the entity, not inside it |
| `list entry field … --get` | `.data.fields` |
| `interaction ls` / `note ls` / `<entity> files ls` | `.data[]` — a **bare array** |
| `note create` / `interaction create` | `.data.note` / `.data.interaction` |
| `field history` / `field changes` / `field history-bulk` | `.data.fieldValueChanges[]` |
| `interaction feed` / `note feed` / `note replies` | `.data.interactions[]` / `.data.notes[]` / `.data.replies[]` |
| `transcript ls` / `transcript get` | `.data.transcripts[]` / `.data.transcript` (`.fragments[]`) |
| `company\|person relationships` / `field options ls` | `.data.relationships[]` / `.data.options[]` |

When in doubt, look before you extract:
`... --json | jq '.data | if type == "object" then keys else "array of \(length)" end'`.

**`null` / missing does not mean empty.** A plain `company get` / `person get` / `opportunity get`
is a cheap lookup that fetches **no field values and no list entries**: `fields: {"requested":
false}` and a missing `listEntries` key mean *not fetched*. `meta.notRequested` names what was
skipped and the flag that fetches it. Never tell the user a record "has no lists" or "empty fields"
— and never offer to write values — without having fetched them.

## Common pitfalls (READ THIS FIRST)

**1. Never redirect stderr to `/dev/null`.** Every CLI safety signal — "results truncated",
"unknown option", "Filtering locally after fetching every entry" — lives on stderr. Dropping stderr is how you ship a
silent-zero-match result and call it a duplicate check.

**2. `--filter` goes through Affinity's search.** On `list export`, `company ls` and `person ls`,
the conditions on fields that Affinity can answer are applied on its side and the whole filter is
checked again locally. When part of it runs locally, `--all`, `--max-results` (or, on `list
export`, `--first-page-only`) is required; the error's `details.local` names those conditions.
`company ls` / `person ls --filter` need a condition on a company/person field (names: `--query`).
Repeating `--filter` ANDs the values; for OR use `|` inside one value.
Details: `references/filtering.md`.

**3. Duplicate checks: use `--company-id` / `--person-id`, not `--filter`.**
`xaffinity list export "Pipeline" --company-id 555 --json` returns 0 or more rows for that exact
company, with its list field values. Zero rows + the emitted warning is the "not on list" signal.

**4. Check `meta.truncated` on every JSON response.** If `true`, the answer is incomplete;
`meta.truncationReason` names the cause (`firstPageOnly`, or `partialFailure` from `field history-bulk`). Separately, Affinity returns at
most 100 values per multi-value field: a `warnings` entry like "Field 'X' … shows 100 of 250 values"
means that field's list is partial, so don't count or dedupe from it.

**5. Side-effecting commands: capture, then parse.** A pipeline like
`xaffinity note create --content "..." --company-id 123 | python3 -c "json.loads(...)"` runs the
create first, then parses. If you forgot `--json`, the parser crashes and the pipeline exits 1 —
but the note was already created, and a "retry" creates a duplicate. Capture first:

```bash
out=$(xaffinity --json note create --content "..." --company-id 123)
note_id=$(printf '%s' "$out" | jq -r '.data.note.id')
```

The CLI also warns on stderr when identical content from the same author arrives within 5
minutes, but that's a safety net — capture-then-parse is the fix.

**6. Person/company field values require numeric IDs, not names.**
`xaffinity list entry field "Pipeline" 999 --set Owner "Jane Doe"` aborts with an "Invalid entity
ID" error before any write. Resolve names to IDs first, and check the ID is not `null`:

```bash
owner_id=$(xaffinity --readonly --json person ls --query "Jane Doe" --max-results 5 \
  | jq -r '.data.persons[0].id')
[ "$owner_id" != "null" ] || { echo "no match for Jane Doe" >&2; exit 1; }
xaffinity list entry field "Pipeline" 999 --set Owner "$owner_id"
```

Every `--set` value is validated before any API call, so one bad value (e.g. a wrong person ID)
means nothing is written. The CLI does not resolve names for you.

## Reading One Company's / Person's Lists and List Fields

```bash
# Which lists is this company on, with each entry's list fields (Status, Owner, ...)
xaffinity --readonly company get 314557093 --expand list-entries --json | jq '.data.listEntries'

# Only one list (--list implies --expand list-entries)
xaffinity --readonly company get 314557093 --list "Dealflow" --json | jq '.data.listEntries'

# Rows for that company on a known list (same values, list-export row shape)
xaffinity --readonly list export "Dealflow" --company-id 314557093 --json | jq '.data.rows'
```

Read `.data.listEntries`, not `.data.company.listEntries`.

## IMPORTANT: Write Operations Require Explicit User Request

**Always use `--readonly` unless the user explicitly requests writes.** Writes include creating,
updating, or deleting notes, interactions, reminders, list entries, field values, persons,
companies and opportunities. Before writing over an existing field value, read it first and show
the user the current value. Write-side gotchas (duplicate refusal on create, read-only and
ambiguous fields, global companies, file uploads): `references/files-and-writes.md`.

## Destructive Commands Require Double Confirmation

Before executing ANY command that cannot be undone (delete, merge):

1. **Look up the entity first** to show the user what will be deleted
2. **Ask the user in your response**, showing the entity details and requesting confirmation
3. **Wait for the user's next message** — do NOT proceed until they explicitly confirm
4. **Only after the user confirms**, run the command with `--yes`

```
User: "Delete person 123"
You: xaffinity --readonly person get 123 --json
You: "This will permanently delete John Smith (ID: 123, email: john@example.com).
      Type 'yes' to confirm deletion."
[Stop here and wait for user's response]

User: "yes"
You: xaffinity person delete 123 --yes
```

**Destructive commands**: `person delete`, `company delete`, `opportunity delete`, `note delete`,
`reminder delete`, `field delete`, `list entry delete`, `interaction delete`, `person merge`,
`company merge` (the duplicate record is removed), `field options delete` (clears that value on
every entry that had it)

The `--yes` flag bypasses the CLI's interactive prompt; the confirmation must come from the user in
the conversation. Without `--yes` and with nothing answering the prompt, these commands fail with a
usage error (exit 2) and change nothing.

## Critical Patterns

| Pattern | Purpose |
|---------|---------|
| `--readonly` | Prevent accidental data modification (ALWAYS use unless writing) |
| `--json` | Structured, parseable output (ALWAYS use for commands you will parse) |
| `--max-results N` | **Limit results (ALWAYS use on list/search commands)**. Aliases: `--limit`, `-n` |
| `--yes` | Skip confirmation on delete and merge commands (use after the user confirms) |
| `--help` | Discover command options (USE THIS, don't guess flags) |

**Always limit results.** Use `--max-results` on every `ls`, `list export`, `interaction ls`, and
`note ls`. Start small (10-50), increase only if needed — unbounded queries can return hundreds of
KB and make many API calls.

**Extract only what you need** with `jq` once you know the shape (see the table above):

```bash
# A person's ID for a follow-up command
xaffinity --readonly person get email:alice@example.com --json | jq -r '.data.person.id'

# Just the fields you need to answer the user
xaffinity --readonly person get 123 --json \
  | jq '.data.person | {id, firstName, lastName, primaryEmailAddress}'

# Entity names from a list export
xaffinity --readonly list export "Pipeline" --max-results 20 --json \
  | jq '[.data.rows[] | {entityName, entityId}]'
```

## Multi-Source Tasks: Use a Script

When a task needs data from **2 or more** CLI commands (e.g., person details + interactions + list
entries), write a **single bash script** that prints only the summary, instead of running commands
one by one — each separate command dumps its full JSON into the conversation. A single command is
fine for simple lookups, single writes and quick searches. Worked example (company → interactions
summary): `references/interactions.md`.

For complex joins across 3+ sources, conditional logic, pagination over large datasets, or SDK
features like `F` filters or `FieldResolver`, write a Python script using the Affinity SDK (the SDK
skill has patterns).

## Selectors: Use Names, Not Just IDs

Most commands accept names, emails, or domains directly — no ID lookup needed:

```bash
xaffinity --readonly person get email:alice@example.com --json
xaffinity --readonly company get domain:acme.com --json
xaffinity --readonly list export "My Pipeline" --max-results 20 --json
xaffinity --readonly person get 12345 --json      # IDs also work
```

## Common Commands

```bash
# Search entities (always limit results)
xaffinity --readonly person ls --query "John Smith" --max-results 10 --json
xaffinity --readonly company ls --query "Acme" --max-results 10 --json

# Lists by name (case-insensitive substring); entries of one list
xaffinity --readonly list ls --query "pipeline" --json
xaffinity --readonly list export "Pipeline" --max-results 20 --json

# Export to CSV
xaffinity --readonly person ls --all --csv --csv-bom > contacts.csv
xaffinity --readonly list export "Pipeline" --all --csv --csv-bom > output.csv
```

Searching and filtering (`--query` vs `--filter`, saved views, operators): `references/filtering.md`.
Content search (max 100, no paging): `note search "text"`, `file search "text"` (inside files), `company search "description"` (semantic; for name/domain use `company ls --query`).
Interactions (types, date ranges, creating them): `references/interactions.md`.
Field change history, org-wide feeds (`interaction feed`, `note feed`), transcripts,
relationships, merge history and dropdown options: `references/history-and-activity.md`.

## List Entry Fields

```bash
# Read specific fields (resolved person/company objects, matching list export format)
xaffinity --readonly list entry field "Pipeline" 12345 --get Owner --get Status --json

# Set a field value (requires write permission)
xaffinity list entry field "Pipeline" 12345 --set Status "Active"
```

`--get` and `--set` are mutually exclusive. `--get` returns resolved objects for person/company
reference fields (`firstName`, `lastName`, `primaryEmailAddress`) and full dropdown option data
(`text`, `color`).

## Expand/Include (N+1 Warning)

`--expand` on `list export` triggers **one additional API call per record**. Use `--max-results`
to control cost.

```bash
# Safe: 20 records = ~21 API calls
xaffinity --readonly list export "Pipeline" --expand persons --max-results 20 --json

# DANGEROUS: --expand with --all on a large list (500 entries = 501+ API calls, ~10 minutes)
# xaffinity list export "Pipeline" --expand persons --all  # DON'T do this blindly
```

**Practical limits:** <=100 records is safe. 200 records ~5 min. 400+ records may hit timeouts.

## Query Command (Advanced)

For aggregation/groupBy, cross-entity filtering, nested AND/OR/NOT, or a cost preview, use
`xaffinity query`. **Always `--dry-run` first** for queries with include/expand/quantifiers. Full
reference (JSON structure, operators, aggregation, examples): `references/query-guide.md`.

| Need | Use |
|------|-----|
| Simple search by name/email | `person ls --query` or `person get email:...` |
| Export list entries | `list export "ListName"` |
| Filter a list by its fields | `list export "ListName" --filter 'Status = "Active"'` |
| Filter companies/persons by their fields | `company ls --filter 'Industry = "Software"' --max-results 50` |
| Aggregate/group data, filter by related entities | `query` |
| Preview API cost first | `query --dry-run` |

## Gotchas & Workarounds

- **Smart fields ("Last Meeting", "Next Meeting") are UI-only.** Use `--with-interaction-dates` on
  **get** commands (not `ls`): `xaffinity --readonly company get domain:acme.com --with-interaction-dates --json`.
- **Internal meetings are NOT in interactions** (only meetings with external contacts) — use notes;
  see `references/interactions.md`.
- **Opportunities are bound to one list.** You cannot search opportunities globally; use
  `list export` on their list. `opportunity get` needs `--details` for field values.
- **Progress output goes to stderr**, so JSON on stdout stays clean. Use `--quiet` / `-q` to
  suppress progress — but don't discard stderr (pitfall 1).
- **Affinity API versions differ.** Results come from the API key's default version unless
  `--api-version` (e.g. `2026-09-17`) / `AFFINITY_API_VERSION` is set; `meta.affinityApiVersion`
  says which answered. Don't add `--api-version` unless the user asks.

## Quick Reference

| Task | Command |
|------|---------|
| Find person by email | `person get email:user@example.com --json` |
| Find company by domain | `company get domain:acme.com --json` |
| Company's lists + list field values | `company get <id> --expand list-entries --json` |
| Is company on list X? (dedup) | `list export "X" --company-id <id> --json` |
| Search people | `person ls --query "name" --max-results 10 --json` |
| Recent interactions | `interaction ls --type all --company-id ID --days 90 --max-results 50 --json` |
| Export list (bounded) | `list export "ListName" --max-results 100 --json` |
| Export list (full CSV) | `list export "ListName" --all --csv --csv-bom > out.csv` |
| List filtered by a field | `list export "ListName" --filter 'Status = "Active"' --json` |
| List through a saved view | `list export "ListName" --saved-view "ViewName" --max-results 50 --json` |
| List entity files | `company files ls "domain:acme.com" --max-results 20 --json` |
| Who changed a field, when | `field history field-123 --company-id <id> --json` |
| What changed since a date (any field) | `field changes --changed-after -7d --max-results 100 --json` |
| Emails / meetings across the org | `interaction feed --type email --after -7d --max-results 50 --json` |
| Recent notes across the org | `note feed --created-after -7d --max-results 50 --json` |
| Who on the team knows a company | `company relationships domain:acme.com --max-results 20 --json` |
| A dropdown's options | `field options ls field-123 --list-id "Pipeline" --json` |
| Aggregate/group data | `query --dry-run --file query.json --json` (preview cost first) |
| Get command help | `xaffinity <command> --help` (USE THIS — don't guess flags) |

**Remember:** prefix all commands with `xaffinity --readonly` (and `--dotenv` if `check-key` says
so). Install: `pip install "affinity-sdk[cli]==2.0.8"`, the version this skill is written for
(`--user` plus the PATH line above when `xaffinity` isn't found); if a command or flag shown
here is missing, the installed CLI is older: install that version. Docs: https://yaniv-golan.github.io/affinity-sdk/latest/

Files in this skill

  • SKILL.md17.2 KB
  • references/files-and-writes.md3.7 KB
  • references/filtering.md5.6 KB
  • references/history-and-activity.md6.2 KB
  • references/interactions.md3.3 KB
  • references/query-guide.md12.1 KB
  • references/setup.md4.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.