0

Im using AdonisJs as my Node Framework, the xeroclient config works perfectly, I can extract details that I need.

I just cant disconnect, as I saw in their sample app we just have to call xero.disconnect, yet i am receiving an error xero.disconnect is not a function

im using the xero-node npm package

const xeroNode = require('xero-node')

const xero = new xeroNode.XeroClient({
  clientId: Config.get('xero.client_id'),
  clientSecret: Config.get('xero.client_secret'),
  redirectUris: [Config.get('xero.redirectUri')],
  scopes: Config.get('xero.scopes').split(" ")
})

async disconnect ({ response, session }) {
   ...
   await xero.disconnect(xero.tenantIds[0])
   ...
}

enter image description here

frost kazuma
  • 350
  • 1
  • 8
  • 24

1 Answers1

0

Only thing that looks incorrect is the parameter you are passing to the function. That should actually be the connection object's ID not the tenantId itself: await xero.disconnect(xero.tenants[0].id)

But other than that can you elaborate the package version you are using? I've just mimicked everything about how you are importing and setting up client, so it's unclear why the disconnect function is not available. Please ensure you are using the most recent version 4.6.0 - the following just worked for me after I successfully got my access token back from the /callback flow.

Setup:

const xeroNode = require('xero-node')

const xero = new xeroNode.XeroClient({
    clientId: client_id,
    clientSecret: client_secret,
    redirectUris: [redirectUrl],
    scopes: scopes.split(' '),
});

/connect

const consentUrl: = await xero.buildConsentUrl();

/callback

const tokenSet = await xero.apiCallback(returning_url);
await xero.updateTenants();

/disconnect

const connection = xero.tenants[0]

await xero.disconnect(connection.id)

If you can post/log some more info can get this sorted for you!

SerKnight
  • 2,502
  • 1
  • 16
  • 18