
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
xero-node
Advanced tools
node version 10.13.0 or higher
version 4 documentation
Version 4.x of Xero NodeJS SDK only supports oAuth2 authentication and the following API sets.
An early release in a separate package is availalbe bank feeds API.
We've moved this code into the oauth1 branch.
Installation This SDK is published as an npm package called xero-node.
npm install --save xero-node
Follow these steps to create your Xero app
A "kitchen sync" app is available that demonstrates interacting with each endpoint. Just download the code and configure.
This is a barebones example showing how to authenticate and display the name of the Xero organisation you've connected to.
'use strict';
const express = require('express');
const session = require('express-session');
const xero_node = require('xero-node')
const port = process.env.PORT || 3000
const client_id = 'YOUR-CLIENT_ID'
const client_secret = 'YOUR-CLIENT_SECRET'
const redirectUri = `http://localhost:${port}/callback`
const scopes = 'openid profile email accounting.transactions accounting.settings offline_access'
const xero = new xero_node.XeroClient({
clientId: client_id,
clientSecret: client_secret,
redirectUris: [redirectUri],
scopes: scopes.split(" ")
});
let app = express()
app.set('port', port)
app.use(express.static(__dirname + '/public'))
app.use(session({
secret: 'something crazy',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
app.get('/', function(req, res) {
res.send('<a href="/connect">Connect to Xero</a>');
})
app.get('/connect', async function(req, res) {
try {
let consentUrl = await xero.buildConsentUrl();
res.redirect(consentUrl);
} catch (err) {
res.send("Sorry, something went wrong");
}
})
app.get('/callback', async function(req, res) {
const url = "http://localhost:5000/" + req.originalUrl;
await xero.setAccessTokenFromRedirectUri(url);
// Optional: read user info from the id token
let tokenClaims = await xero.readIdTokenClaims();
const accessToken = await xero.readTokenSet();
req.session.tokenClaims = tokenClaims;
req.session.accessToken = accessToken;
req.session.xeroTenantId = xero.tenantIds[0];
res.redirect('/organisation');
})
app.get('/organisation', async function(req, res) {
try {
const response = await xero.accountingApi.getOrganisations(xero.tenantIds[0])
res.send("Hello, " + response.body.organisations[0].name);
} catch (err) {
res.send("Sorry, something went wrong");
}
})
app.listen(port, function() {
console.log("Your Xero basic public app is running at localhost:" + port)
})
src/
|- gen/ autogenerated TypeScript
`- *.ts handwritten TypeScript
dist/ compiled JavaScript
package.json
FAQs
Xero NodeJS OAuth 2.0 client for xero-node
The npm package xero-node receives a total of 51,986 weekly downloads. As such, xero-node popularity was classified as popular.
We found that xero-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.