# Export AI spend to QuickBooks Online

> Connect QuickBooks Online by signing in with Intuit, choose the accounts once, then close each month in one click as a journal entry or a bill.

Source: https://immiscible.fly.dev/docs/guides/quickbooks

The same monthly close as [Xero](https://immiscible.fly.dev/docs/guides/xero.md), into QuickBooks Online. One difference matters: **QuickBooks has no draft journal entries or draft bills**, so the document is created for review in QuickBooks, and the console says so.

## 1. Connect

**Connect** on the QuickBooks card sends you to Intuit to pick the company and approve the `com.intuit.quickbooks.accounting` scope. Intuit returns the company id (`realmId`), which every call uses. Access tokens last an hour; refresh tokens rotate, and Immiscible always seals the newest and refreshes one at a time.

## 2. Choose the accounts once

- **Post as**: a journal entry (debit the expense account, credit a liability) or a bill from a vendor you pick.
- **A line per**: team, or cost centre.
- Accounts and vendors are picked from your live lists (`select * from Account`, `select * from Vendor`).
- **Currency**: the company's home currency (`CurrencyPrefs.HomeCurrency`), converted from USD at the European Central Bank's rate, month end or the month's average, exactly as [for Xero](https://immiscible.fly.dev/docs/guides/xero.md#currency); or, for a bill, USD as recorded (a USD vendor and multi-currency on).

## 3. Close a month

Idempotent, three ways over, as for Xero: one row per month; a lookup for a `JournalEntry` or `Bill` whose `DocNumber` is `IMM-YYYY-MM`; and Intuit's `requestid` on every create, so a request sent twice creates one document. Calls use `minorversion=75`. Retries and the `accounting_export` ledger record are as for Xero.

## For the operator: register the Intuit app once

1. At [developer.intuit.com](https://developer.intuit.com), My Hub, App dashboard, create an app with the **QuickBooks Online Accounting** scope.
2. Settings, **Redirect URIs**: add `https://<your PUBLIC_URL host>/connect/quickbooks/callback` under Production (https only, no IP addresses). Development keys may use `http://localhost`.
3. Keys and credentials: copy the client id and secret into `INTUIT_CLIENT_ID` and `INTUIT_CLIENT_SECRET`. Production keys appear once Intuit approves the production key questionnaire. To test with development keys against sandbox companies, set `INTUIT_ENVIRONMENT=sandbox`.

Sources: [OAuth 2.0](https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/oauth-2.0), [discovery document](https://developer.api.intuit.com/.well-known/openid_configuration), [JournalEntry](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry), [Bill](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/bill), [requestid](https://developer.intuit.com/app/developer/qbo/docs/learn/learn-basic-field-definitions), [minor versions](https://developer.intuit.com/app/developer/qbo/docs/learn/explore-the-quickbooks-online-api/minor-versions), [redirect URIs](https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/set-redirect-uri).
