xero-node-bankfeeds
Advanced tools
Comparing version 0.9.0 to 0.9.1
{ | ||
"name": "xero-node-bankfeeds", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "NodeJS client for Xero bank feeds API with OAuth 2.0 support", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,3 +9,3 @@ # xero-node-bankfeeds | ||
Installation | ||
This SDK is published as an npm package called xero-node. | ||
This SDK is published as an npm package called xero-node-bankfeeds. | ||
@@ -32,3 +32,3 @@ ```sh | ||
## Typescript example | ||
A "kitchen sync" app is available that demonstrates interacting with each endpoint. | ||
A "kitchen sync" app is available that demonstrates interacting with "feedconnections" endpoint. | ||
Just [download the code](https://github.com/XeroAPI/xero-node-oauth2-app) and configure. | ||
@@ -40,2 +40,24 @@ | ||
Start with an empty folder | ||
### Initialze your app | ||
```sh | ||
npm init | ||
``` | ||
### Install dependencies | ||
```sh | ||
npm install --save xero-node-bankfeeds | ||
``` | ||
```sh | ||
npm install express --save | ||
``` | ||
```sh | ||
npm install express-session --save | ||
``` | ||
Create your index.js using the code below - don't forget to add your client id and secret | ||
```js | ||
@@ -46,3 +68,3 @@ 'use strict'; | ||
const session = require('express-session'); | ||
const xero_node = require('xero-node') | ||
const xero_node_bankfeeds = require('xero-node-bankfeeds'); | ||
@@ -52,10 +74,10 @@ const client_id = 'YOUR-CLIENT_ID' | ||
const redirectUri = 'http://localhost:5000/callback' | ||
const scopes = 'openid profile email accounting.transactions accounting.settings offline_access' | ||
const scopes = 'openid profile email bankfeeds offline_access' | ||
const xero = new xero_node.XeroClient({ | ||
clientId: client_id, | ||
clientSecret: client_secret, | ||
redirectUris: [redirectUri], | ||
scopes: scopes.split(" ") | ||
}); | ||
const xeroClient = new xero_node_bankfeeds.XeroBankFeedClient({ | ||
clientId: client_id, | ||
clientSecret: client_secret, | ||
redirectUris: [redirectUri], | ||
scopes: scopes.split(" "), | ||
}); | ||
@@ -79,3 +101,3 @@ let app = express() | ||
try { | ||
let consentUrl = await xero.buildConsentUrl(); | ||
let consentUrl = await xeroClient.buildConsentUrl(); | ||
res.redirect(consentUrl); | ||
@@ -89,19 +111,34 @@ } catch (err) { | ||
const url = "http://localhost:5000/" + req.originalUrl; | ||
await xero.setAccessTokenFromRedirectUri(url); | ||
await xeroClient.setAccessTokenFromRedirectUri(url); | ||
// Optional: read user info from the id token | ||
let tokenClaims = await xero.readIdTokenClaims(); | ||
const accessToken = await xero.readTokenSet(); | ||
let tokenClaims = await xeroClient.readIdTokenClaims(); | ||
const accessToken = await xeroClient.readTokenSet(); | ||
req.session.accessToken = tokenClaims; | ||
req.session.tokenClaims = tokenClaims; | ||
req.session.accessToken = accessToken; | ||
req.session.xeroTenantId = xero.tenantIds[0]; | ||
res.redirect('/organisation'); | ||
res.redirect('/feedconnections'); | ||
}) | ||
app.get('/organisation', async function(req, res) { | ||
app.get('/feedconnections', async function(req, res) { | ||
try { | ||
const response = await xero.accountingApi.getOrganisations(xero.tenantIds[0]) | ||
res.send("Hello, " + response.body.organisations[0].name); | ||
} catch (err) { | ||
const accessToken = req.session.accessToken; | ||
await xeroClient.setTokenSet(accessToken); | ||
// CREATE | ||
var feedConnection = new xero_node_bankfeeds.FeedConnection(); | ||
feedConnection.accountName = "SDK Test Account"; | ||
feedConnection.accountNumber = "123321"; | ||
feedConnection.accountToken = "foobar321"; | ||
feedConnection.accountType = xero_node_bankfeeds.FeedConnection.AccountTypeEnum.BANK; | ||
feedConnection.currency = xero_node_bankfeeds.CurrencyCode.GBP; | ||
const feedConnections = new xero_node_bankfeeds.FeedConnections(); | ||
feedConnections.items = [feedConnection]; | ||
const response = await xeroClient.bankFeedsApi.createFeedConnections(xeroClient.tenantIds[0], feedConnections); | ||
res.send("Bank account create with ID: " + response.body.items[0].id ); | ||
} catch (err) { | ||
console.log(err.body); | ||
res.send("Sorry, something went wrong"); | ||
@@ -108,0 +145,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136465
155