Automated AI Accounts Payable: Docsumo to Xero (n8n)

Eliminate manual data entry by extracting invoice data with AI and syncing directly to Xero as Draft Bills via n8n.

Tools: DocsumoXero

Platform: n8n

Short Answer

A fully automated pipeline where validated Docsumo documents instantly appear as Draft Bills in Xero. n8n handles the complex array transformation for line items, attaches the original PDF, and ensures data integrity with automated vendor matching.

The Problem

Manual entry of invoice data into accounting systems is time-consuming and prone to human error, especially when handling complex line items. Relying on manual uploads often delays financial visibility and increases the risk of duplicate payments.

The Outcome

A fully automated pipeline where validated Docsumo documents instantly appear as Draft Bills in Xero. n8n handles the complex array transformation for line items, attaches the original PDF, and ensures data integrity with automated vendor matching.

Step-by-Step Guide

1. **Setup Docsumo Webhook**: Create a 'Webhook' node in n8n. Copy the production URL and paste it into Docsumo Under Settings > Webhooks, selecting the 'Document Status Changed' event. 2. **Configure Credentials**: In n8n, navigate to Settings > Credentials. Create new credentials for 'Xero OAuth2' and 'Docsumo API'. Follow the Xero app creation process in the Xero Developer Portal to get your Client ID and Secret. 3. **Filter for 'Validated' Status**: Add an 'IF' node after the Webhook. Set the condition to check if the status equal `validated`. This prevents draft or failed extractions from entering your accounting books. 4. **Search/Create Contact**: Use the 'Xero' node with the 'Contact: Get All' resource. Filter by the vendor name extracted from Docsumo. If no contact is returned, use a second Xero node to 'Create' the contact to avoid 'Contact ID not found' errors. 5. **Format Line Items for Xero**: Add a 'Code' node or 'Set' node to transform the Docsumo `line_items` array. Xero requires an array of objects containing `Description`, `Quantity`, `UnitAmount`, and `AccountCode`. Use `{{ $json["data"]["extracted_data"]["line_items"].map(item => ({ ... })) }}` syntax. 6. **Create Bill (n8n Xero Node)**: Add a Xero node. Select 'Purchase Invoice' resource and 'Create' operation. Map the Contact ID from Step 4 and the mapped Line Items from Step 5. Set the status to 'DRAFT' for safe review. 7. **Handle Attachments**: Use the 'HTTP Request' node to download the original document URL provided by Docsumo (set response to 'File'). Connect it to a Xero node using the 'File: Upload' resource, linking it to the Bill ID created in the previous step. 8. **Error Handling**: Create an 'Error Trigger' workflow or use the 'On Error' -> 'Flow to Error Node' setting on the Xero node to catch API rate limits or mapping failures.

Data Mapping

| Docsumo Field | Xero Field | n8n Expression / Transformation | | :--- | :--- | :--- | | `vendor_name` | `ContactName` | `{{ $json.data.extracted_data.vendor_name }}` | | `invoice_number` | `Reference` | `{{ $json.data.extracted_data.invoice_number }}` | | `date` | `Date` | `{{ $now.format('yyyy-MM-dd') }}` (or extracted date) | | `due_date` | `DueDate` | `{{ $json.data.extracted_data.due_date }}` | | `line_items` | `LineItems` | Mapped via Code Node to Xero Object Schema | | `currency` | `CurrencyCode` | `{{ $json.data.extracted_data.currency ?? 'USD' }}` | | `doc_url` | `Attachment` | Downloaded via HTTP Node, then uploaded to Xero |

Gotchas & Failure Modes

• **Rate Limiting**: Xero has a limit of 60 requests per minute. Use n8n's 'Wait' node or 'Split in Batches' if processing large backlogs of documents at once. • **Date Formats**: Xero is sensitive to date formats. Use the n8n 'Date & Time' node or `.format('yyyy-MM-dd')` to ensure compatibility. • **Tax Types**: Ensure the `TaxType` code in your mapping exactly matches your Xero Settings (e.g., 'INPUT' vs 'OUTPUT'). Missing this often causes 400 Bad Request errors. • **Attachment Timeout**: Large PDFs may timeout on the HTTP Request node. Increase the timeout limit in node 'Settings' if handling high-res scans.

Verification Checklist

- [ ] Webhook successfully receives a JSON payload from Docsumo when a test document is 'Validated'. - [ ] IF Node correctly filters out 'In-Progress' documents. - [ ] Search Contact node returns an ID for existing vendors and successfully triggers contact creation for new ones. - [ ] The Code Node outputs an array of Line Items in the format: `[{"Description": "...", "UnitAmount": 10.00}]`. - [ ] Xero node creates a 'Draft' bill with the PDF attached in the 'Files' side-bar of the transaction. - [ ] n8n 'Execution Log' shows green success indicators for all nodes in the path.

Ready to Automate?

Build this automation with n8n in minutes.