Qb Crm Enrichment

Task Details
← Task Board

Task Description

# TASK: QuickBooks CRM Enrichment — Sync Financial Data to Contacts

**Priority:** LOW
**Agent:** engineer
**Filed:** 2026-02-20
**Filed by:** Doug (via Claude Code session)

---

## Goal

Run the CRM enrichment script to pull QuickBooks financial data into the local contacts database and generate a dashboard summary.

## What to Run

```bash
cd /data/Sandbox/QuickBooks
python crm_enrichment.py --enrich --summary
```

## What It Does

1. **Pulls all QB customers** (543+) with balances, emails, names
2. **Pulls all invoices** (up to 1000) and computes per-customer stats
3. **Matches QB customers to local contacts** (by email, then by name)
4. **Enriches contacts.json** with: `ar_balance`, `qb_customer_id`, `total_invoiced`, `last_invoice_date`, `open_invoices`, `open_amount`, `qb_status`
5. **Generates dashboard data** at `farmiq.ai/dashboard/qb_data.js`
6. **Generates summary JSON** at `QuickBooks/data/crm_summary.json`

## Environment Required

QB credentials must be in environment variables:
```bash
export QB_CLIENT_ID=ABEVR8EKciLgXQsV6d4RdhAF2CsRU7m0UNTHYPpiBbr5dsaz0Z
export QB_CLIENT_SECRET=CFztIPnePpgwTI0FQlX7ZPyAXk8niRraugJbcqfy
```

Or tokens must already exist at `QuickBooks/data/qb_tokens.json`.

## After Running

- Commit the updated contacts.json and dashboard files
- If auth fails, post to dashboard: "QB tokens expired — Doug needs to re-auth"
- Deploy dashboard: `python /data/Sandbox/farmiq.ai/deploy.py --upload`

## Schedule

Run this weekly (Sunday night) or on-demand when Doug requests it.
Should NOT run more than once per day (each run makes ~5 API calls).

## DO NOT
- Do NOT modify qb_client.py or crm_enrichment.py
- Do NOT send any emails about the results
- Do NOT run --enrich without --summary (always generate both)

Job Queue (0)

No job queue entries for this task yet