A fully automated pipeline that captures orders from your multi-channel tool, handles complex tax logic via n8n expressions, and ensures every sale is recorded as a paid invoice in Xero with 100% accuracy.
The Problem
Manually reconciling high-volume sales from multiple marketplaces (Amazon, eBay, Shopify) into Xero is time-consuming and prone to human error. Businesses struggle to map varying tax rates and prevent duplicate contact/invoice creation, leading to messy financial reporting.
The Outcome
A fully automated pipeline that captures orders from your multi-channel tool, handles complex tax logic via n8n expressions, and ensures every sale is recorded as a paid invoice in Xero with 100% accuracy.
Step-by-Step Guide
1. **Create Webhook Trigger**: Start your n8n workflow with a 'Webhook' node. Set the HTTP Method to POST. This will receive real-time order data from your Multi-Channel tool.
2. **Configure Multi-Channel Credentials**: Add an HTTP Request node to pull full order details if the webhook payload is partial. Authenticate using 'Header Auth' or 'OAuth2' depending on your tool (e.g., Linnworks/ChannelAdvisor).
3. **Sanitize Data with 'Set' Node**: Use a 'Set' node to normalize fields. Use expressions like `{{ $json["total"].toNumber() }}` to ensure price fields are numbers, and trim whitespace from emails.
4. **Check for Existing Contact**: Add a 'Xero' node. Select the 'Contact' resource and 'Get All' operation. Use a filter expression: `email == {{ $json.customer_email }}`.
5. **Logic Branching (If Node)**: Use an 'If' node to check if the Xero search returned a result. If false, route to a 'Xero: Create Contact' node; if true, proceed to mapping.
6. **Map Line Items with Code**: Use a 'Code' node or complex expressions in a 'Set' node to transform your platform's line items into Xero's required format: `[{ "Description": "Item A", "Quantity": 1, "UnitAmount": 10.00, "TaxType": "OUTPUT" }]`.
7. **Dynamic Tax Mapping**: Use a 'Switch' node to look at the `shipping_country` field. Route 'US' to one tax code and 'UK' to another to ensure VAT/Sales Tax compliance.
8. **Create Sales Invoice**: Add a 'Xero' node, resource 'Invoice', operation 'Create'. Link the Contact ID from previous steps and the line items array.
9. **Apply Payment**: To close the invoice, add another 'Xero' node. Resource 'Payment', operation 'Create'. Map the `InvoiceID` from the previous step and specify the 'Bank Account ID' (e.g., your clearing account).
10. **Global Error Handling**: Create a separate workflow with an 'Error Trigger' node. Connect it to a 'Slack' or 'Email' node to notify you if an invoice fail due to a locked accounting period or API timeout.