xero-node (QA Beta)
Release of SDK with oAuth 2 support
Version 4.x of Xero NodeJS SDK only supports oAuth2 authentication and the following API sets.
- accounting
- bank feeds
Coming soon
- fixed asset
- files
- payroll
- projects
- xero hq
Usage
Installation
npm install xero-node-sdk
Getting Started
Create a Xero App
Follow these steps to create your Xero app
- Create a free Xero user account (if you don't have one)
- Login to Xero developer center
- Click "Try oAuth2" link
- Enter your App name, company url, privacy policy url.
- Enter the redirect URI (this is your callback url - localhost, etc)
- Agree to terms and condition and click "Create App".
- Click "Generate a secret" button.
- Copy your client id and client secret and save for use later.
- Click the "Save" button. You secret is now hidden.
Example
; const client_id = 'YOUR-CLIENT_ID'const client_secret = 'YOUR-CLIENT_SECRET'const redirectUri = 'http://www.yourdomain.com/callback'const scopes = 'openid profile email accounting.transactions offline_access' const xero = clientId: client_id clientSecret: client_secret redirectUris: redirectUri scopes: scopes ; // Get authorization for userlet consentUrl = await xeroClient; // Redirect user's browser to the consentUrl// User will login to Xero and grant your app access// User will be returned to the redirectUri (aka Callback URL) //On callback - get token from Xero//Get the query string (i.e. with express req.query)await xero; // Optional: read user info from the id tokenlet tokenClaims = await xeroClient; //Call the Xero APIlet apiResponse = await xeroaccountingApi;console; // Refresh the token when it expiresawait xeroClient;
Project Structure
src/
|- gen/ autogenerated TypeScript
`- *.ts handwritten TypeScript
dist/ compiled JavaScript
package.json