xero-node-sdk
TypeScript icon, indicating that this package has built-in type declarations

4.0.0-beta5 • Public • Published

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

import { XeroClient } from "xero-node-sdk";
 
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 = new XeroClient({
        clientId: client_id,
        clientSecret: client_secret,
        redirectUris: [redirectUri],
        scopes: scopes.split(" ")
      });
 
// Get authorization for user
let consentUrl = await xeroClient.buildConsentUrl();
 
// 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.setAccessTokenFromRedirectUri(req.query);
 
// Optional: read user info from the id token
let tokenClaims = await xeroClient.readIdTokenClaims();
  
//Call the Xero API
let apiResponse = await xero.accountingApi.getInvoices(xero.tenantIds[0]);
console.log("Invoices[1]: ", apiResponse.body.invoices[0].invoiceID);
 
// Refresh the token when it expires
await xeroClient.refreshToken();

Project Structure

src/
  |-  gen/        autogenerated TypeScript
  `-  *.ts        handwritten TypeScript
dist/             compiled JavaScript
package.json

Readme

Keywords

none

Package Sidebar

Install

npm i xero-node-sdk

Weekly Downloads

2

Version

4.0.0-beta5

License

MIT

Unpacked Size

2.14 MB

Total Files

755

Last publish

Collaborators

  • sidneyallen