【问题标题】:Xero API 403 - AuthenticationUnsuccessful errorXero API 403 - AuthenticationUnsuccessful 错误
【发布时间】:2020-05-21 14:32:46
【问题描述】:

我将 Xero Api 与 Nodejs 和 xero-node 库一起使用。

我已完成 oAuth 流程并将令牌保存到数据库中。我现在遇到的问题是在尝试从 Xero 获取联系人、帐户或用户的任何内容时,不断收到 403 禁止错误。示例代码如下

我可以毫无问题地让租户满意,但其他任何事情都不起作用。我检查了范围以确保在设置客户端时它们是正确的。

var getStuff = async(tokenSet) => {
  await xero.setTokenSet(tokenSet);
  const tenants = await xero.updateTenants();

  const xeroTenantId = tenants[0].id  // {String} Xero identifier for Tenant
  const ifModifiedSince = new Date("2020-02-06T12:17:43.202-08:00");
  const where =  'IsSubscriber==true';  // {String} Filter by an any element
  const order =  'LastName ASC';  // {String} Order by an any element

  console.log(tenants);
  try {
    const response  = await xero.accountingApi.getUsers(xeroTenantId, ifModifiedSince, where, order);
    console.log(response.body || response.response.statusCode)

  }
  catch (err) {

   /// console.log(err);

    console.log(`There was an ERROR! \n Status Code: ${err.response.statusCode}.`);
    console.log(`ERROR: \n ${JSON.stringify(err.response.body, null, 2)}`);

  }

}

【问题讨论】:

    标签: node.js xero-api


    【解决方案1】:

    哪些范围已添加到您正在传递的访问令牌中?你可以在这里解码你的令牌https://jwt.io/

    另外 - 您需要将“tenant.tenantId”传递给函数。我相信tenant.id 实际上与从 /connections 端点返回的连接 id 相关。

    我的直觉是这就是问题所在。也很好奇它是如何工作的,因为 updateTenants() 最后应该有一个空函数调用。这对你有用吗?

    【讨论】:

    • 好的,我正准备删除这个问题,因为我已经解决了。出于某种原因,也许它的锁定我只是使用了“.id”,而我应该一直在寻找的是“tenantId”,正如你正确指出的那样谢谢
    • 常见的误解。在这方面,连接的概念与租户略有不同。很高兴你把它整理好了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2014-07-13
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多