Socket
Socket
Sign inDemoInstall

xero-node

Package Overview
Dependencies
Maintainers
4
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xero-node

NodeJS Client for the Xero API, supporting OAuth2 Apps


Version published
Weekly downloads
55K
decreased by-6.96%
Maintainers
4
Weekly downloads
 
Created
Source

xero-node (alpha)

Release of SDK with oAuth 2 support

Version 4.x of Xero NodeJS SDK only supports oAuth2 authentication and the following API sets.

  • accounting

Coming soon

  • fixed asset
  • bank feeds
  • 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

FAQs

Package last updated on 30 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc