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
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);