This repository contains an example Linx solution demonstrating how to implement and use the Xero Authentication Service. The solution provides a practical implementation for connecting to the Xero API, retrieving tenant information, and fetching accounting data such as balance sheets.
The example showcases the proper authentication flow with Xero, token management, and making authenticated API calls - all using the Linx Xero Authentication Service plugin.
- Clone this repository to your local machine
- Open the solution using Linx Designer
- Configure the required settings (see Configuration section below)
- Debug the solution
- Linx Designer (latest version)
- Access to a database for storing authentication tokens
- A registered Xero application with API credentials
- A Xero user with active company (Demo Company will work)
Before running the solution, you need to configure the following settings:
- XeroAuthURL: The service URI for handling the authorization. The service will listen for incoming requests at
[authorization-uri]/authorize
- XeroRedirectURL: The URI to which users will be redirected after the authorization process is complete
- XeroClientID: Client ID from your registered Xero application
- XeroClientSecret: Client secret from your registered Xero application
- XeroDatabaseConnection: Database connection string where the authentication tables will be created to store client tenant and token information
- XeroBaseURI: The base URI for Xero API calls
Important: In your Xero application settings, set the Redirect URI to
[authorization-uri]/callback
The solution includes the following key components:
The core authentication service that handles OAuth 2.0 authorization with Xero. This service is documented in the Linx Xero Authentication Service documentation.
This function demonstrates the proper usage of the Xero Authentication Service:
- Set the
XeroUserIDToBeUsed
variable with the Xero User ID - Call
StartServiceXeroAuth
to start the service (only required when running in debug mode) - Call
GetTenants
to retrieve available tenants - Loop through tenants and call
GetBalanceSheet
for each one
This function demonstrates how to call the Xero Balance Sheet API and process the response. It:
- Makes an authenticated API call to Xero's Balance Sheet endpoint
- Processes the response and assigns it to a typed object
- Returns the balance sheet data
To authenticate a client and obtain a User ID:
- Configure the solution with your Xero app credentials
- Run the solution in debug mode using
ExampleMainFunction
- Visit the Authorization URI in your browser (
[XeroAuthURL]/authorize
) - Follow the authentication flow as described in the Xero Authentication Service documentation
- After successful authentication, retrieve the User ID for future API calls
Data types for the API responses are stored in the Types folder. These can be:
- Imported directly from documentation
- Created by debugging API calls as strings, then importing the JSON response as a new type
For questions and support, please ask the Linx community.