Xero API:创建新商品时出现错误“ The PurchasesAccountId帐户无效”

时间:2020-05-21 03:32:13

标签: node.js adonis.js xero-api

我只是尝试创建新项目,只是在示例应用程序上复制了语法,但是我似乎无法创建新项目,我看不到确切的错误,感谢您的提前帮助!

请注意,我正在使用试用版xero帐户,不确定是否这样。

我使用xero-node来使用xero api。

const Config = use('Config')
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(" ")
})

try {
    const item1 = {
      code: "Foo" + '123',
      name: "Bar",
      purchaseDetails: {
        unitPrice: 375.5000,
        taxType: "NONE",
        accountCode: "500"
      },
      salesDetails: {
        unitPrice: 520.9900,
        taxType: "NONE",
        accountCode: "400",
      }
    }

    const newItems = new xeroNode.Items()
    newItems.items = [item1]

    const itemCreateResponse = await xero.accountingApi.createItems(xero.tenants[0].tenantId, newItems)
  } catch (error) {
    console.log(error.response.toJSON())
  }

以下是响应的正文(error.response.toJSON()。body): enter image description here

这是验证错误(error.response.toJSON()。body.ValidationErrors):

[ { Message: 'The PurchasesAccountId account is invalid.' } ]

1 个答案:

答案 0 :(得分:0)

发生此错误的原因有很多:

  • 该帐户不存在
  • 该帐户已存档
  • 该帐户是用于跟踪库存的专用库存资产帐户。资产帐户跟踪您现有库存的价值,因此不应用于交易。 PurchasesAccountID应该是专用的AP帐户。

希望这会有所帮助。

相关问题