Xero-OpenAPI icon indicating copy to clipboard operation
Xero-OpenAPI copied to clipboard

problem with function .getClientCredentialsToken()

Open BryanGH-Wix-Velo opened this issue 3 years ago • 2 comments

Hi, We are using a npm package: https://www.npmjs.com/package/xero-node npm: xero-node to integrate a Wix website with Xero only to create Invoices. But following the documentation it says that we have to use the getClientCredentialsToken method and that it can only be done with custom connections (The app is called AppLatino). We already have the custom connection but when we run the function we get this error message:

"xero.getClientCredentialsToken is not a function".

We are implementing this:

import { XeroClient } from 'xero-node'; export async function xeroJs() { const xero = new XeroClient({ clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET',

}); try { await xero.initialize() return await xero.getClientCredentialsToken()

} catch (error) {
    console.log(error)
    return error
}

}

Therefore please:

  1. We would like support please to understand why we are not able to execute this function we are getting that error: "xero.getClientCredentialsToken is not a function".

Appreciate your prompt support, please.

BryanGH-Wix-Velo avatar Jun 16 '22 19:06 BryanGH-Wix-Velo

I just ran this sample app with no issues, the method worked as expected. It looks like you're using Velo for developing your integration? Without seeing more of your project structure it's tough to say, however, there are a number of possible causes for is not a function error.

RettBehrens avatar Jun 16 '22 20:06 RettBehrens

Hello @RettBehrens Yes, I use Wix Velo to code in Wix in a backend .js file having previously imported the Xero-node npm import { XeroClient } from 'xero-node'. The call to the method is direct through a button

export async function xeroJs() {

const xero = new XeroClient({
    clientId: 'CLIENT_ID',
    clientSecret: 'CLIENT_SECRET'
});

try {
    await xero.initialize()
    let tokenSet = await xero.getClientCredentialsToken();
    return tokenSet

} catch (error) {
    console.log(error)
    return error
}

}

The code that is called is the previous one with the secret keys without the grant type. Following the npm documentation

import { XeroClient } from 'xero-node';

const xero = new XeroClient({ clientId: 'YOUR_CLIENT_ID', clientSecret: 'YOUR_CLIENT_SECRET', grantType: 'client_credentials' });

const tokenSet = await xero.getClientCredentialsToken(); // save the tokenSet

const invoices = await xero.accountingApi.getInvoices('');

But the response I get is as follows "xero.getClientCredentialsToken is not a function" We want to know if we need any other library or if more connections are needed prior to this sample code

BryanGH-Wix-Velo avatar Jul 06 '22 02:07 BryanGH-Wix-Velo

Closing as this actually is not relevant for this repo. If it remains an issue please open an issue on Xero-Node repo

RettBehrens avatar Oct 14 '22 06:10 RettBehrens