Xero SDK without using all the auth part

Hi,

I’m looking to use the Xero SDK (npm ‘xero-node’) inside a workflow step. Pipedream is already doing all the authentication part and the SDK needs a configuration object with the token. Is there a way i can use Pipedream authentication with Xero SDK ?
Example of SDK authentication: https://github.com/XeroAPI/xero-node

Thanks

Hello @mkures,

First off, welcome to Pipedream! Happy to have you!

You can use Node code step sample “Use integrated API authentication” for this,

It will give you an example for Github, which you can change to xero_accounting_api for your usecase

Replying to myself:

To be able to use the Xero SDK inside pipedream, you only have to rename the tokenSet produced by pipedream.

//Import the SDK
import { XeroClient } from 'xero-node';
// create a client object
const xero = new XeroClient();
// Use the auth data from pipedream
const tokenSet = this.xero_accounting_api.$auth;
//Rename or create the object attributes for Xero
  tokenSet.id_token=tokenSet.oauth_uid;
    tokenSet.access_token=tokenSet.oauth_access_token;
    tokenSet.token_type="Bearer";
    tokenSet.refresh_token=tokenSet.oauth_refresh_token;
//choose your needed scope
    tokenSet.scope=["email", "profile", "openid", "accounting.transactions", "offline_access"]
    tokenSet.expires_in=1800;
// set the token set
    await xero.setTokenSet(tokenSet);

and then the SDK is functional.

for example try:

await xero.updateTenants();
const activeTenantId = xero.tenants[0].tenantId;
// GET all Accounts
const getAccountsResponse = await xero.accountingApi.getAccounts(activeTenantId);

Captura

1 Like

Hi @mkures

Sounds like the Python scaffolding for Xero broken out of the box, could you please file a bug report here: Sign in to GitHub · GitHub

We’d be happy to take a closer look and get that fixed so you won’t have to apply this every time.