Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for Xero consists of three basic steps:
- Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
- Provide the driver class. For example:
cdata.jdbc.xero.XeroDriver
- Provide the JDBC URL. For example:
jdbc:xero:InitiateOAuth=GETANDREFRESH; or jdbc:cdata:xero:InitiateOAuth=GETANDREFRESH;
The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:xero:" or "jdbc:cdata:xero:" and can include any of the connection properties in name-value pairs separated with semicolons.
Connecting to a Xero API
The driver supports the following Xero APIs:
- Accounting API: Set the Schema connection property to ACCOUNTING
- Australian Payroll API: Set the Schema connection property to PAYROLLAUS
- Files API: Set the Schema connection property to FILES
- Fixed Assets API: Set the Schema connection property to ASSETS
- Projects API: Set the Schema connection property to PROJECTS
It is also recommended that you set the Tenant property, which can be the name or ID of a Xero organization. Xero allows you to authorize the driver to access multiple organizations. By default the driver will pick the first one, which may not be the one you expect if the driver is granted access to additional organizations.
If you need to confirm what organizations the driver has access to, you can connect without an Tenant and read the Tenants view. This will provide both the ID and the name of each connected organization. You should use the ID to set the Tenant property when possible since multiple organizations can have the same name.
Authenticating to Xero
All connections to Xero are authenticated using OAuth. The driver supports using PKCE applications and OAuth applications. For desktop applications, the driver's embedded application is the simplest way to authenticate. The only requirement is to set InitiateOAuth to GETANDREFRESH.
When the driver starts, it will open a browser and Xero will request your login information. The driver will use the credentials you provide to access your Xero data. These credentials will be saved and automatically refreshed as needed. For desktop applications, the driver's default application is the simplest way to authenticate. The only additional requirement is to set InitiateOAuth to GETANDREFRESH.
When the driver starts, it will open a browser and Xero will request your login information. The driver will use the credentials you provide to access your Xero data. These credentials will be saved and automatically refreshed as needed.