0

Im just trying to create new items, just copied the syntax on your sample app, but i cant seem to create new Items, I dont see exactly whats the error, thanks for the help in advance!

Take note that I am using a trial xero account, not sure if thats the case tho.

im using xero-node to use the 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())
  }

Here is the body of the response (error.response.toJSON().body): enter image description here

Here is validation error (error.response.toJSON().body.ValidationErrors):

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

frost kazuma
  • 350
  • 1
  • 8
  • 24
  • Do you actually have accounts with code "400" and "500" in your trial organisation? – droopsnoot May 21 '20 at 08:39
  • Also in the doc, `AccountCode` has a capital A. Might that cause trouble? I find that when parsing Xero's JSON responses in VB, they are case-sensitive. That said, UnitPrice is capitalised too. – droopsnoot May 21 '20 at 09:44

1 Answers1

0

There are several reasons this error can occur:

  • the account does not exist
  • the account is archived
  • the account is a dedicated inventory asset account for tracked inventory. The assets account tracks the value of your stock on hand and as such shouldn't be used for transactions. The PurchasesAccountID should be a dedicated AP account.

Hope this helps.

Dan
  • 1,489
  • 12
  • 16