{"data":{"slug":"discovered-61edbca8566b9cb0333bf1e6a06619cece8be705bb2f1d9f","title":"Accounting Sync: FreeAgent <-> Spark <-> Paperless-ngx","summary":"Synchronizes bank transactions from FreeAgent with invoices found through Spark, uploads them to Paperless-ngx, and attaches them back to FreeAgent. Use this skill for weekly accounting maintenance or when the user asks to 'sync invoices' or 'connect FreeAgent and Paperless'.","url":"https:\/\/skillshunter.net\/skills\/discovered-61edbca8566b9cb0333bf1e6a06619cece8be705bb2f1d9f","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-61edbca8566b9cb0333bf1e6a06619cece8be705bb2f1d9f","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-61edbca8566b9cb0333bf1e6a06619cece8be705bb2f1d9f.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-61edbca8566b9cb0333bf1e6a06619cece8be705bb2f1d9f\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running the skill, ensure that Spark Desktop is running, CLI access is enabled, and the accounting-evidence account `dan.webb@damacus.io` is listed. Also, verify that `freeagent-cli auth status` returns exit code 0 and `expired=false`. In dry-run mode, no uploads or attachments should occur, and only candidate items should be enumerated.","instructions":"---\nname: accounting-sync\ndescription: Synchronizes bank transactions from FreeAgent with invoices found through Spark, uploads them to Paperless-ngx, and attaches them back to FreeAgent. Use this skill for weekly accounting maintenance or when the user asks to \"sync invoices\" or \"connect FreeAgent and Paperless\".\n---\n\n# Accounting Sync: FreeAgent <-> Spark <-> Paperless-ngx\n\nThis skill automates the workflow of matching bank transactions with their corresponding invoices and ensuring they are archived in Paperless-ngx and linked in FreeAgent.\n\n## Core Workflow\n\n### 0. Mandatory Auth Preflight\nRun this before any dry-run or real-mode work. If either Spark or FreeAgent is unavailable, stop and report the blocker. Do not continue to mailbox searches, FreeAgent reads, Paperless checks, or local file staging.\n\n- `spark accounts`\n  - Required: Spark Desktop is running, CLI access is enabled, and the accounting-evidence account `dan.webb@damacus.io` (damacus.io) is listed.\n  - Optional: `dan.m.webb@gmail.com` (personal Gmail) and `daniel.webb@equalexperts.com` (EE) may be listed when their scoped workflows are needed; do not block routine accounting sync if either is absent.\n  - Run through keychain\/network-capable execution when the sandbox cannot reach the Spark Desktop bridge.\n- `freeagent-cli auth status`\n  - Required: exit code 0 and `expired=false`.\n  - If the CLI reports `no tokens stored`, stop and ask the user to reauthenticate FreeAgent.\n- `paperless status`\n  - Required for real mode.\n  - In dry-run mode, a Paperless failure may be reported as a Paperless-only blocker, but do not upload or attach anything.\n\nThe auth preflight is step zero because partial runs create noise: mailbox-only or FreeAgent-only scans cannot prove whether an item is ready to sync.\n\n### 1. Establish Run Mode and Date Window\n- Confirm whether the run is dry-run or real mode.\n- Use the requested window. If the user does not specify one, default to the past 7 days.\n- Record the exact window in the final report, for example `2026-04-16 through 2026-04-30`.\n\n### 2. Identify Target Transactions\n- Query FreeAgent for unexplained or recently explained transactions in the date window.\n- Prefer the primary active business bank account unless the user specifies another account.\n- Reference `references\/vendors.json` to filter transactions from known sources.\n- Include recently explained transactions with `has_attachment=false`; those are often the main sync targets.\n- Example:\n  - `freeagent-cli --json bank-accounts list`\n  - `freeagent-cli --json bank list --bank-account BANK_ACCOUNT_URL --from YYYY-MM-DD --to YYYY-MM-DD --per-page 100`\n  - `freeagent-cli --json bank review get BANK_TRANSACTION_URL`\n\n### 3. Search Spark for Invoices\n- Use account-scoped Spark searches. The normal accounting-evidence account is `dan.webb@damacus.io`; do not search the personal Gmail account by default.\n- `dan.m.webb@gmail.com` (Gmail) is for personal mail and EE-Timesheet OTPs, not routine accounting evidence.\n- `daniel.webb@equalexperts.com` (EE) is for consultancy correspondence. Search it only when a transaction is clearly EE-related or the user asks for consultancy evidence.\n- For each target transaction, use the vendor's `gmail_query` from `references\/vendors.json` as Spark's Gmail-style `--filter` value.\n- Match emails by date (within +\/- 3 days) and amount (considering currency conversion if applicable).\n- Use a broad attachment search for the same window to catch vendors not yet in the config:\n  - `spark search --in dan.webb@damacus.io --filter '(receipt OR invoice) has:attachment after:YYYY\/MM\/DD before:YYYY\/MM\/DD' --page-size 50`\n- Use vendor-specific searches for known vendors:\n  - `spark search --in dan.webb@damacus.io --filter 'from:vendor@example.com subject:invoice after:YYYY\/MM\/DD' --page-size 10`\n\n### 4. Extract and Validate PDFs\n- If a matching email has a PDF attachment:\n  - Read the full thread to identify the attachment IDs: `spark thread MESSAGE_ID`.\n  - Download only the business invoice or receipt PDF, not terms and conditions or marketing attachments.\n  - `spark attachment ATTACHMENT_ID --stream > \/Users\/damacus\/receipts\/paperless\/FILENAME.pdf`\n- Store staged PDFs under `\/Users\/damacus\/receipts\/paperless\/` using the original invoice or receipt filename when possible.\n- Verify before upload or attachment:\n  - `file \/Users\/damacus\/receipts\/paperless\/FILENAME.pdf`\n  - Required: `PDF document`, expected file size, and the expected vendor amount visible in the email body or extracted text.\n\n### 5. Search Paperless Before Uploading\n- Search by invoice number, receipt number, vendor, and amount before uploading.\n- If Paperless already has the document, do not upload a duplicate; use the existing document as the archive evidence and continue to FreeAgent attachment if needed.\n- Examples:\n  - `paperless --output json search query 'AKD-736127147787'`\n  - `paperless --output json search query '2171 4358'`\n\n### 6. Upload to Paperless\n- In real mode, upload the verified PDF with IDs resolved from the user's local Paperless instance.\n- Treat `references\/vendors.json` as semantic configuration, not an ID registry:\n  - Use `default_paperless_profile` and `paperless_profiles` for shared user\/work tags, such as `Work`.\n  - Use the vendor's `paperless_profile` to select those shared tags.\n  - Use `paperless_correspondent` for the document sender\/vendor, falling back to `name` if it is absent.\n  - Use `paperless_tags` for vendor or domain tags, such as `anthropic`, `AI`, `DNS`, or `accounting`.\n  - Resolve every tag, correspondent, and document type name to the user's local Paperless IDs before upload.\n  - Do not assume numeric Paperless IDs are portable between users or instances.\n- Example:\n  - `paperless --output json document upload PDF_PATH --title 'TITLE' --type-id TYPE_ID --correspondent-id VENDOR_CORRESPONDENT_ID --tag-id YEAR_TAG_ID --tag-id PROFILE_TAG_ID --tag-id VENDOR_TAG_ID`\n- If Paperless returns `database is locked`, wait briefly and retry once. If the retry also fails, stop and report the Paperless blocker without re-attaching the same receipt again.\n\n### 7. Link Back to FreeAgent\n- For an already explained transaction with no attachment, attach the verified PDF to the existing explanation.\n- Prefer the review helper over delete\/re-create when available:\n  - `freeagent-cli --json bank review attach-receipt --explanation EXPLANATION_URL --file PDF_PATH --approve`\n- Only use delete\/re-create when the helper is unavailable or the existing explanation cannot accept an attachment.\n- Never attach if amount, date, and vendor do not all match.\n- Never attach terms and conditions PDFs.\n\n### 8. Post-Mutation Verification\nAfter each real-mode sync, verify both sides before reporting success:\n\n- FreeAgent:\n  - `freeagent-cli --json bank review get BANK_TRANSACTION_URL`\n  - Required: `has_attachment=true`, expected filename, and `marked_for_review=false` if `--approve` was used.\n- Paperless:\n  - Search by invoice or receipt number.\n  - Required: one matching document and the expected title\/content.\n- Final report:\n  - List synced items with transaction ID, explanation ID, Paperless document ID, and attachment filename.\n  - List skipped items and why they were skipped.\n  - List blockers separately from skipped non-target transactions.\n\n## Vendor Configuration\nSee [references\/vendors.json](references\/vendors.json) for the list of known vendors and their matching rules.\n\n## Security & Reliability\n- Auth preflight is mandatory in dry-run and real mode.\n- Always verify the amount, date, and vendor before attaching a document.\n- Always verify the staged file is a PDF before uploading or attaching.\n- Search Paperless before uploading to avoid duplicates.\n- Handle `database is locked` errors in Paperless by retrying once with a short delay.\n- Use dry-run mode to enumerate candidates only; do not stage partial evidence as a substitute for authentication.\n- In real mode, mutate one matched item at a time and verify it before moving to the next.\n","use_cases":["Weekly accounting maintenance","Syncing invoices between FreeAgent and Paperless-ngx","Connecting FreeAgent and Paperless-ngx for document management"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/damacus\/skills\/blob\/5706f70c0058822adf29da9bd7620c7ea780b9d6\/skills\/operations\/accounting-sync\/SKILL.md","source_commit":"5706f70c0058822adf29da9bd7620c7ea780b9d6","license":null,"version":null,"listing_approved_at":"2026-12-02","created_at":"2026-11-30T08:54:30.000000Z","updated_at":"2026-12-02T09:15:01.000000Z","seo_title":"Accounting Sync: FreeAgent <-> Spark <-> Paperless-ngx","seo_description":"Automates the workflow of matching bank transactions with their corresponding invoices and ensuring they are archived in Paperless-ngx and linked in FreeAgent.","seo_keywords":["accounting sync","FreeAgent integration","Spark integration","Paperless-ngx","invoice synchronization","document management"]}}