> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thredfi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AR Integration

> Sync invoices, payments, and refunds

## Why Integrate AR?

Your platform tracks invoices. Thred turns them into financial intelligence:

* **Revenue recognition** - P\&L updates as invoices are sent/paid
* **Cash flow tracking** - Outstanding invoices = predictable cash inflows
* **Auto-reconciliation** - Bank payments match to invoices automatically

## What to Send

**Invoices** - Revenue transactions
[`POST /v1/platform/businesses/{id}/invoices/`](/api-reference/invoices/create-invoice)
When: Invoice created in your system
Why: Starts the AR cycle, recognizes revenue

**Invoice Payments** - Customer payments
[`POST /v1/platform/businesses/{id}/invoices/payments/`](/api-reference/payments/create-payment)
When: Payment received (bank transfer, card, cash)
Why: Reduces AR balance, updates cash position

**Refunds** - Customer credits
[`POST /v1/platform/businesses/{id}/invoices/refunds/`](/api-reference/refunds/create-refund)
When: Order canceled, overpayment, return
Why: Reverses revenue, creates refund payable

**Refund Payments** - Outbound refunds
[`POST /v1/platform/businesses/{id}/invoices/refunds/{refund_id}/payments/`](/api-reference/refund-payments/create-refund-payment)
When: Money sent back to customer
Why: Clears refund liability

## Integration Patterns

**Pattern 1: Invoice-first** (SaaS, professional services)

```
1. User creates invoice in your app
2. POST invoice to Thred
3. Customer pays → POST payment
4. Done: Revenue recognized, AR cleared
```

**Pattern 2: Payment-first** (e-commerce, retail)

```
1. Customer pays at checkout
2. POST invoice + payment together
3. Return/cancel → POST refund + refund payment
4. Done: Revenue and refunds tracked
```

## Example: Create Invoice

```python theme={null}
invoice_data = {
    "external_id": f"invoice-{your_invoice_id}",
    "customer_id": customer_id,
    "invoice_number": "INV-001",
    "sent_at": "2026-06-11T10:00:00Z",
    "due_at": "2026-07-11T10:00:00Z",
    "line_items": [
        {
            "description": "Monthly Subscription",
            "quantity": 1,
            "unit_price": 9900,  # £99.00 in minor units
            "tax_code": "EXEMPT"
        }
    ]
}

response = requests.post(
    f"https://sandbox.thredfi.com/v1/platform/businesses/{business_id}/invoices/",
    headers={"Authorization": f"Bearer {business_token}"},
    json=invoice_data
)
```

Use [`GET /v1/platform/businesses/{id}/tax-codes/`](/api-reference/tax-codes/list-tax-codes) before sending taxable invoices. Unknown tax codes are rejected, and taxable line items are rejected for customers marked `tax_exempt`.

## Example: Record Payment

```python theme={null}
payment_data = {
    "external_id": f"payment-{your_payment_id}",
    "invoice_id": invoice_id,
    "amount_cents": 9900,
    "payment_date": "2025-01-20",
    "payment_method": "bank_transfer"
}

response = requests.post(
    f"https://sandbox.thredfi.com/v1/platform/businesses/{business_id}/invoices/payments/",
    headers={"Authorization": f"Bearer {business_token}"},
    json=payment_data
)
```

## Priority

Start with:

1. **Invoices** - Essential for revenue tracking
2. **Payments** - Track what's been paid
3. **Refunds** (if applicable) - Handle returns

Skip credit notes and write-offs initially. Add later if needed.

Next: Connect bank accounts for automated transaction sync.
