# Export rules
Source: https://docs.file.ai/deliver/export-rules

> Send processed files to Google Drive, Xero, QuickBooks and other apps with export rules you manage through the API.

Exports

# Export rules

Copy pageCopy page

Send processed files to Google Drive, Xero, QuickBooks and other apps with export rules you manage through the API.

Copy pageCopy page

An export rule sends the files in one or more folders to another app, such as a Google Drive folder or your Xero organization. You create and change rules through the API, run them on the files you choose, and read each file’s outcome. Rules made through the API are the same rules the fileAI app shows under its export settings, so you can manage them in either place.

## [](#when-to-use-it)When to use it

*   You process files through the API and want the results to land in your accounting or storage app without anyone opening fileAI.
*   You set up many folders the same way and want to script their export settings instead of clicking through the app.
*   You need to know, per file, whether an export reached the other app and why it didn’t.

## [](#how-it-works)How it works

1

Connect the app in fileAI

The account for each app (your Xero organization, your Google account) is connected once per organization in the fileAI app. The API can’t connect an account, because the app’s own sign-in page has to be shown to a person. `GET /v1/export-connections` shows which accounts are connected.

2

Create a rule

A rule names the **integration**, the **folders** whose files it exports, and the integration’s **options**: where files go and how they’re written. It can also be limited to one contact or one file type. Each integration publishes the options it takes as a JSON Schema in `GET /v1/export-integrations`.

3

Export files

With `autoExport` on, a file in the rule’s folders is exported as soon as it is processed. To export files now, run the rule on them. A run is an [async job](/api/async-jobs#export-jobs) with an `exjob_` id that you poll.

4

Check the outcome

The job lists each file as `EXPORTED`, `FAILED` or `SKIPPED`, with a reason when it isn’t `EXPORTED`. `GET /v1/files/{fileId}/exports` shows a file’s latest export, whichever rule or person started it.

### [](#which-rule-applies-to-a-file)Which rule applies to a file

A file is covered by a rule when it is in one of the rule’s folders and matches the rule’s contact and file type. A rule with no contact or no file type matches any. If several rules for the **same** integration cover a file, the most specific one wins: contact and file type, then contact only, then file type only, then neither. Rules for **different** integrations all apply, so an invoice can go to Xero through an invoice rule and to Google Drive through a rule for any file type. A folder can’t hold two rules with the same contact and file type, even for different integrations: the second returns `409 CONFLICT`. A Wafeq bank statement rule needs a folder of its own.

### [](#endpoints)Endpoints

Method and path

What it does

`GET /v1/export-integrations`

List the integrations and each one’s `optionsSchema`.

`GET /v1/export-connections`

List the accounts connected for export, `connected` or `disconnected`.

`POST /v1/export-rules`

Create a rule. Requires an `Idempotency-Key`.

`GET /v1/export-rules`

List rules, newest first. Filter by `folderId` or `integration`.

`GET /v1/export-rules/{ruleId}`

Read one rule.

`PATCH /v1/export-rules/{ruleId}`

Change a rule, or pause it with `autoExport: false`.

`DELETE /v1/export-rules/{ruleId}`

Stop a rule.

`POST /v1/export-rules/{ruleId}/run`

Export files now with this rule. Requires an `Idempotency-Key`. Returns `202` with a job.

`GET /v1/jobs/{job_id}`

Poll a run.

`GET /v1/files/{fileId}/exports`

Read a file’s latest export.

NetSuite exports are set up through the fileAI connector app, not these endpoints.

## [](#example)Example

Export a processed invoice as JSON into a Google Drive folder. The cURL commands assume `FILEAI_BASE_URL="https://api.orion.file.ai/prod/v1"`, or your [regional host](/authentication#regions).

1

Check the integration and its connection

```
curl "$FILEAI_BASE_URL/export-integrations" -H "x-api-key: $FILEAI_API_KEY"
curl "$FILEAI_BASE_URL/export-connections" -H "x-api-key: $FILEAI_API_KEY"
```

Find `GoogleDrive` in the first list and read its `optionsSchema`: a `format` of `excel` or `json`, and a `destination.folderId`. The second list must show `{ "integration": "GoogleDrive", "status": "connected" }`. If it doesn’t, connect Google Drive in the fileAI app first.

2

Create the rule

The Drive folder id is the last part of the folder’s link: `https://drive.google.com/drive/folders/1AbCdEfGhIjKlMnOpQrStUvWxYz`.

```
curl -X POST "$FILEAI_BASE_URL/export-rules" \
  -H "x-api-key: $FILEAI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "integration": "GoogleDrive",
    "folderIds": ["6630f1c2a1b2c3d4e5f60718"],
    "autoExport": false,
    "options": {
      "format": "json",
      "destination": { "folderId": "1AbCdEfGhIjKlMnOpQrStUvWxYz" }
    }
  }'
```

The response is the saved rule, with its `id`. Keep `autoExport` off while you test; turn it on later with `PATCH`.

3

Run the rule on a file

```
curl -X POST "$FILEAI_BASE_URL/export-rules/$RULE_ID/run" \
  -H "x-api-key: $FILEAI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "fileIds": ["6630f1c2a1b2c3d4e5f60aa1"] }'
```

```
{
  "job_id": "exjob_3f2a1b4c7e8d4c1fa0b39d2e5f6a7b8c",
  "status": "queued",
  "created_at": "2026-11-26T02:14:00.000Z",
  "poll_url": "https://api.orion.file.ai/prod/v1/jobs/exjob_3f2a1b4c7e8d4c1fa0b39d2e5f6a7b8c"
}
```

4

Poll the job until it settles

```
curl "$FILEAI_BASE_URL/jobs/exjob_3f2a1b4c7e8d4c1fa0b39d2e5f6a7b8c" -H "x-api-key: $FILEAI_API_KEY"
```

```
{
  "job_id": "exjob_3f2a1b4c7e8d4c1fa0b39d2e5f6a7b8c",
  "kind": "export",
  "status": "COMPLETED",
  "rule_id": "6630f1c2a1b2c3d4e5f60799",
  "files": [
    {
      "file_id": "6630f1c2a1b2c3d4e5f60aa1",
      "status": "EXPORTED",
      "external_url": null,
      "document_number": null,
      "error": null
    }
  ],
  "created_at": "2026-11-26T02:14:00.000Z",
  "updated_at": "2026-11-26T02:14:21.000Z",
  "settled_at": "2026-11-26T02:14:21.000Z",
  "error": null
}
```

`COMPLETED` means every file has an outcome, not that every file was exported: check each file’s `status`. `external_url` links to the exported record when the integration reports one, as Xero does for a bill. Google Drive doesn’t report one.

A file’s latest export stays readable after the job, from any rule or from the app:

```
curl "$FILEAI_BASE_URL/files/6630f1c2a1b2c3d4e5f60aa1/exports" -H "x-api-key: $FILEAI_API_KEY"
```

```
{
  "fileId": "6630f1c2a1b2c3d4e5f60aa1",
  "status": "EXPORTED",
  "publishedTo": null,
  "externalUrl": null,
  "documentNumber": null,
  "error": null
}
```

## [](#options-for-each-integration)Options for each integration

`options` must match the integration’s `optionsSchema`: required fields present, values from the allowed lists, and no unknown field names. Each problem comes back as its own item in a `422` response, with a `pointer` such as `#/options/destination/folderId`. For Xero and QuickBooks, values such as an account code or tax rate are also checked against the data fileAI has synced from your account, when it has some. The examples below are a starting point for each integration. Values in capitals are placeholders for ids from your own account. `optionsSchema` lists every field and the allowed values.

*   Google Drive
    
*   Google Sheets
    
*   OneDrive
    
*   Xero
    
*   QuickBooks
    
*   Wafeq
    
*   Odoo
    

Writes each file as Excel (`excel`) or JSON (`json`) into a Drive folder. The folder id is the last part of the folder’s link.

```
{
  "format": "json",
  "destination": { "folderId": "YOUR_DRIVE_FOLDER_ID" }
}
```

Adds rows to a sheet. In `https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit#gid=0`, the spreadsheet id is the part after `/d/`, and `gid` is the `sheetId`. `sheetTitle` is the tab’s name.`typeExport` picks what goes in: `allFieldsToExport`, `allTablesToExport`, `allToExport`, or `custom` with at least one entry in `fieldsToExport` or `tablesToExport`.

```
{
  "typeExport": "allFieldsToExport",
  "spreadsheetId": "YOUR_SPREADSHEET_ID",
  "sheet": { "sheetId": 0, "sheetTitle": "Sheet1" }
}
```

Writes each file as `xlsx`, `xls`, `csv`, `json` or `pdf` into a OneDrive folder.

```
{
  "format": "xlsx",
  "destination": { "folderId": "YOUR_ONEDRIVE_FOLDER_ID" }
}
```

Creates a Xero document. `ExportDocument` picks which: `Invoice`, `Purchase` (a bill), `Purchase Order`, `Bank Transaction`, `Credit Note`, `Expense Claim`, `Manual Journal` or `Payment`. Each one has its own required fields, such as `InvoiceStatus` for `Invoice` and `Purchase`, and `Account` for everything except `Payment` and `Manual Journal`. `Account` is the Xero account code.A draft bill with one line for the total:

```
{
  "ExportDocument": "Purchase",
  "TypeOfExport": "total",
  "AmountType": "Exclusive",
  "InvoiceStatus": "DRAFT",
  "Account": "YOUR_ACCOUNT_CODE"
}
```

See [Xero export](/deliver/xero-export) for connecting Xero.

Creates a QuickBooks document. `ExportDocumentType` is one of `Invoice`, `CreditMemo`, `Bill`, `JournalEntry`, `Expense`, `SalesReceipt`, `VendorCredit`, `Estimate` or `Purchase`, and `TypeOfExport` is `header` (one line), `items` or `itemsSeparate`. An `Invoice` or `SalesReceipt` exported as `items` or `itemsSeparate` also needs `TypeOfExportNegativeAmount`, and an `Estimate` needs `EstimateStatus`.A bill with one line for the total:

```
{
  "ExportDocumentType": "Bill",
  "TypeOfExport": "header",
  "Account": "YOUR_QUICKBOOKS_ACCOUNT_ID"
}
```

Creates a Wafeq `Bill` (the default) or `Invoice`, or imports a `BankStatement`. A bill or invoice needs `Account`. A bill’s status is `DRAFT` or `AUTHORIZED`; an invoice’s is `DRAFT` or `SENT`. A bank statement needs `BankAccount` and a `StartDate` (`yyyy-MM-dd`) instead.

```
{
  "ExportDocument": "Bill",
  "InvoiceStatus": "DRAFT",
  "AmountType": "TAX_EXCLUSIVE",
  "TypeOfExport": "header",
  "Account": "YOUR_WAFEQ_ACCOUNT_ID"
}
```

Creates a draft vendor bill. `account` and `vendor` are Odoo record ids, as numbers. `currency` is optional; `0` means none.

```
{
  "ExportDocument": "Vendor Bill",
  "InvoiceStatus": "draft",
  "account": 101,
  "vendor": 7
}
```

A Google Drive or OneDrive folder id is not checked when the rule is saved. A wrong id is only found when a file is exported, and the export fails. Copy the id from the folder’s link.

## [](#change-pause-or-delete-a-rule)Change, pause or delete a rule

*   **Change.** `PATCH` changes only the fields you send. `options`, when sent, **replaces** the saved options as a whole, so send the full set, not just the field you’re changing. The integration can’t change; create a new rule instead.
*   **Pause.** `PATCH` with only `{ "autoExport": false }` stops automatic exports. It works even when the integration has been disconnected. Turning it back on runs the same checks as creating a rule.
*   **Delete.** `DELETE` stops the rule. As in the app, the rule goes back to being a suggestion the app may offer again. Files already exported are not touched.

## [](#reference)Reference

### [](#rule-fields)Rule fields

Field

Description

`integration`

Integration id from `GET /v1/export-integrations`, such as `GoogleDrive` or `Xero`. Required on create; can’t change.

`folderIds`

Folders whose files the rule exports, 1 to 100.

`contactId`

Only files from this contact in the workspace. `null` or left out for any contact.

`schemaId`

Only files of this file type: the `blueprintId` of a schema from `GET /v1/schemas`, not its `id`. The file type must be approved. `null` or left out for any file type.

`autoExport`

Export matching files automatically once they’re processed. Default `false`.

`options`

The integration’s settings. Must match its `optionsSchema`.

### [](#run-statuses)Run statuses

A run’s job (`kind: "export"`) has one of these statuses:

`status`

Meaning

`QUEUED`

Accepted, not started. Poll again.

`RUNNING`

Files are being sent. Poll again.

`COMPLETED`

Every file has an outcome. Some may be `FAILED` or `SKIPPED`. Never changes again.

`FAILED`

The run itself failed; see `error`. Never changes again.

Each entry in `files` has one of these statuses:

File `status`

Meaning

`EXPORTING`

Sent; waiting for the integration’s answer.

`EXPORTED`

The integration accepted it.

`FAILED`

The integration rejected it, or no answer came back; see `error`.

`SKIPPED`

Not sent; see `error` for why.

### [](#reasons)Reasons

`error.code`

Where

Meaning

`RULE_NOT_APPLICABLE`

File, `SKIPPED`

The rule doesn’t cover the file (another folder, contact or file type), or a more specific rule for the same integration does.

`NO_FILE_TYPE`

File, `SKIPPED`

The file has no file type yet, so no rule can apply to it.

`ALREADY_EXPORTING`

File, `SKIPPED`

The file is already being exported. Run it again once that finishes.

`MAPPING_FAILED`

File, `SKIPPED`

The file’s fields couldn’t be mapped to the integration’s fields.

`FILE_NOT_FOUND`

File

The file doesn’t exist in this workspace, or was deleted before the export reported back.

`EXPORT_FAILED`

File, `FAILED`

The integration rejected the file. `detail` carries its messages.

`EXPORT_TIMED_OUT`

File, `FAILED`

No answer came back from the integration within 24 hours. Check the file’s export status.

`EXPORT_NOT_STARTED`

Job, `FAILED`

The run didn’t start within 60 minutes. Run it again.

`EXPORT_STATUS_UNKNOWN`

Job, `FAILED`

The run stopped reporting within 30 minutes of starting. Check each file’s export status before running it again.

### [](#errors)Errors

Code

Status

When

`INTEGRATION_NOT_CONNECTED`

409

The integration’s account isn’t connected. Connect it in the fileAI app.

`CONFLICT`

409

A rule for the same folders, contact and file type already exists, or the integration isn’t available for this workspace (on run).

`CONCURRENT_UPDATE`

409

The folder’s export settings are being changed by another save. Retry.

`VALIDATION_FAILED`

422

A field or option is invalid, a file in `fileIds` doesn’t exist, or the integration rejected the settings. Each problem is its own item in `errors`.

`UPSTREAM_ERROR`

502

The service that talks to the integrations returned an error or didn’t answer.

See [Errors](/api/errors) for the response format.

### [](#limits)Limits

*   Up to 100 folders per rule and 100 files per run. Repeated ids count once.
*   A run exports a file again even if it was exported before.
*   `GET /v1/export-rules` returns 50 rules per page by default; a `limit` above 100 returns 100. See [Pagination](/api/pagination).
*   A file keeps only its latest export. There is no export history yet.
*   Suggested rules the app hasn’t confirmed are not listed.

## [](#next-steps)Next steps

## Async jobs

How export jobs are polled alongside other jobs.

## Idempotent requests

Retry a create or run safely with the same key.

## MCP tools

Set up and run exports from an AI assistant.

## API reference

Every export endpoint, field and response.

[Previous](/ask/agent-sessions)[

Folders

Group files into folders in the app or with the directories API, without duplicating them.

Next

](/ingest/folders)

⌘I

## On this page

Back to top

*   [When to use it](#when-to-use-it)
*   [How it works](#how-it-works)
    *   [Which rule applies to a file](#which-rule-applies-to-a-file)
    *   [Endpoints](#endpoints)
*   [Example](#example)
*   [Options for each integration](#options-for-each-integration)
*   [Change, pause or delete a rule](#change-pause-or-delete-a-rule)
*   [Reference](#reference)
    *   [Rule fields](#rule-fields)
    *   [Run statuses](#run-statuses)
    *   [Reasons](#reasons)
    *   [Errors](#errors)
    *   [Limits](#limits)
*   [Next steps](#next-steps)
