Set up the Xero Bank Feeds integration
Set up our integration with Xero Bank Feeds
Before you can write bank feeds to Xero, you need to set up the Xero accounting integration in the Codat Portal.
This article explains how to:
- Create a company and a data connection to Xero.
- Provide Codat with source bank accounts you want to make available for your SMB users to connect to.
- Redirect the user to the Codat-provided account mapping UI, where they can connect their source bank accounts to target bank accounts in Xero.
Prerequisites
Before setting up the integration, make sure that:
-
You've set up the Xero integration. The main tasks are as follows:
- In the Xero Developer portal, create and configure a Xero app.
- Retrieve your app's secure keys and then add them to the integration.
Bank feeds functionality is part of our existing Xero accounting integration and uses the same Redirect URI.
-
Xero have enabled the Xero Bank Feeds API for your registered app.
Create a company and data connection, then add bank accounts
-
Using the
POST /companies
endpoint, create a company to represent your SMB user:Create a companyPOST https://api.codat.io/companies
Request body{
"name": "<COMPANY_NAME>"
}The endpoint returns a JSON response containing the company ID (
id
) and the redirect URL (redirect
). -
Using the
POST /companies/{companyId}/connections
endpoint, create a data connection to Xero for the company you added. Specify the company ID in the URL path and the Xero platform key in the body:Create connectionPOST https://api.codat.io/companies/{companyId}/connections
Request body - Xero{
"platformKey": "gbol"
}The endpoint returns a
dataConnection
object inPendingAuth
status, containing a connectionid
and alinkUrl
. Later, you'll use thelinkUrl
to redirect the SMB user to the account mapping UI.Response example - Create connection (200){
"id": "9d0703c1-fc71-43b7-b4e0-37cd7a863644",
"integrationId": "0f20c943-12d0-4800-9f6c-d218f62d494c",
"integrationKey": "gbol",
"sourceId": "8a156a5a-39cb-4f9d-856e-76ef9b9a9607",
"platformName": "Xero",
"linkUrl": "https://link-api.codat.io/companies/...",
"status": "PendingAuth",
"created": "2023-05-10T08:40:26.0000000Z",
"sourceType": "Accounting"
} -
Using the
POST /bankFeedAccounts
endpoint, add one or more source bank accounts:Create bank feed bank accountsPOST /companies/{companyId}/connections/{connectionId}/connectionInfo/bankFeedAccounts
For the
{connectionId}
, use the connectionid
you received in the response fromPOST /connection
request.In the request body, specify a source bank account to make available to the SMB user. For example, to add a credit card account send the following request:
Request body (all fields are required)
{
"id": "acc-002", // set to desired unique ID
"accountName": "account-081",
"sortCode": "123456",
"accountType": "Debit",
"accountNumber": "12345670",
"currency": "GBP",
"balance": 99.99 // can be 0
}Specific account typesXero approves Bank Feeds applications only for "BANK" or "CREDITCARD" account types (in Xero's terminology). Therefore, it's important to use the correct
accountType
value when setting up source bank accounts, namely "Debit" for type "BANK" and "Credit" for type "CREDITCARD". -
The endpoint returns a
200
code and the created bank account.
Read next
Learn how your SMB users can connect their bank accounts to Xero using the account connection UI.