Shopify Order to Xero Invoice Automation (n8n)

Seamlessly sync e-commerce sales to your accounting ledger using n8n's flexible workflow engine.

Tools: ShopifyXero

Platform: n8n

Short Answer

A fully automated workflow in n8n that triggers on new Shopify orders, verifies customer existence in Xero to prevent duplicates, creates a draft invoice with correct line items, and logs errors to a dedicated channel for manual review.

The Problem

Manual entry of Shopify orders into Xero is time-consuming and prone to human error, leading to inaccurate financial reporting and tax discrepancies. Business owners often struggle with duplicate contacts and inconsistent tax mapping between sales and accounting platforms.

The Outcome

A fully automated workflow in n8n that triggers on new Shopify orders, verifies customer existence in Xero to prevent duplicates, creates a draft invoice with correct line items, and logs errors to a dedicated channel for manual review.

Step-by-Step Guide

1. **Create Shopify Webhook**: Add a 'Shopify Trigger' node. Set the event to `Order Created`. Connect your Shopify credentials using an API Access Token and the shop URL. 2. **Filter Paid Orders**: Add an 'IF' node after the trigger. Set the condition to check if `financial_status` equals `paid`. This ensures you only sync revenue-ready data. 3. **Search for Existing Contact**: Add a 'Xero' node. Select the 'Contact' resource and 'Get All' operation. Use a filter expression: `EmailAddress == "{{ $json.customer.email }}"`. 4. **Conditional Contact Creation**: Add an 'IF' node to check if the Xero search returned any results. If empty, add another Xero node with the 'Create' operation to generate a new contact using Shopify name and email data. 5. **Format Line Items**: Add a 'Set' node or use the 'Code' node to map Shopify's `line_items` array into the format Xero requires (Description, Quantity, UnitAmount, AccountCode, TaxType). 6. **Create Sales Invoice**: Add a Xero node with the 'Invoice' resource and 'Create' operation. Map the Contact ID from the previous steps, use the Shopify order name as the reference, and pass the formatted line items array. 7. **Apply Payment**: To close the invoice, add a final Xero node with the 'Payment' resource and 'Create' operation. Map the `InvoiceID` and the total order amount to mark it as reconciled. 8. **Configure Error Handling**: Right-click the workflow canvas and select 'Create Error Workflow'. This ensures that if the Xero API is down or data is malformed, you receive an execution notification.

Data Mapping

| Shopify Field (Source) | Xero Field (Destination) | n8n Expression / Transformation | | :--- | :--- | :--- | | `customer.email` | `Contact.EmailAddress` | `{{ $json.customer.email }}` | | `name` | `Invoice.Reference` | `{{ $json.name }}` (e.g., #1001) | | `line_items[*]` | `Invoice.LineItems` | Use `.map()` in a Code node for array transformation | | `total_price` | `Payment.Amount` | `{{ Number($json.total_price) }}` | | `created_at` | `Invoice.Date` | `{{ $now.toFormat('yyyy-MM-dd') }}` | | `N/A` | `AccountCode` | Hardcode 200 (Sales) or use a lookup table node |

Gotchas & Failure Modes

• **Rate Limiting**: Xero has a limit of 60 calls per minute. If processing bulk historical orders, enable 'Limit' or 'Split In Batches' node in n8n. • **Rounding Discrepancies**: Shopify and Xero calculate tax differently. It is highly recommended to send 'Tax Inclusive' unit prices to Xero and let Xero back-calculate the tax to avoid penny-off errors. • **OAuth Refresh**: Ensure your n8n instance has a public-facing URL (via tunnel or static IP) so Xero's OAuth2 token refresh callback works correctly. • **Memory Management**: If using a Code node to process hundreds of line items, ensure your n8n Docker container has at least 1GB of RAM allocated.

Verification Checklist

- [ ] **Trigger Test**: Create a $0.00 'Draft' order in Shopify and mark as paid to trigger the webhook. - [ ] **Data Check**: In n8n, inspect the 'Output' of the Set node to ensure line items are an array of objects. - [ ] **Credential Check**: Ensure the Xero connection shows 'Connected' in the node settings. - [ ] **Xero Verification**: Log into Xero 'Draft Invoices' to confirm the invoice was created with the correct Contact and Reference. - [ ] **Execution Log**: Check the n8n Execution History to ensure no nodes are highlighted in red.

Ready to Automate?

Build this automation with n8n in minutes.