Xero API (Using .Net Standard SDK) Problem when creating bank account

39 Views Asked by At

I am integrating with the xero API, I have a token which was requested with the following scopes

openid profile email offline_access files accounting.transactions accounting.contacts accounting.settings

I am running the following code :

var bankAccount = await _accountingApi.CreateAccountAsync(token.AccessToken, token.Tenants.FirstOrDefault()?.ToString(), new Account
{
    Type = AccountType.BANK,
    BankAccountType = Account.BankAccountTypeEnum.BANK,
    Name = "Clearing Account",
    BankAccountNumber = "00000000"
}, null, cancellationToken);

However when this executes I get a 403 error returned.

From what I have read in the docs this should work, the Account PUT notes in the Xero docs suggest that Im right, I just cant get it to work - what am I missing?

2

There are 2 best solutions below

2
Doel Jangkrik On BEST ANSWER

Did you also get a Ref number with the HTTP 403 response? If so, it can be used by Xero API Support to find the exact cause.

There are a few reasons why you could be hitting a 403.

  • The Access Token being used is expired and must be refreshed
  • The Tenant ID being used in the headers is missing
  • The user has revoked access
  • The Tenant is no longer active
0
5NRF On

For anyone struggling with this in the future its not clear in the docs (or at least wasnt to me) but when you are creating a bank account the BankAccountNumber property should be "sort code [space] account number"

Because I was creating a clearing account not an actual bank account (no open banking etc) I had been told that the account number should just be zeros - it was not clear that a. The sort code is to be included in the account number field. b. When creating a clearing account the sort code also has to be zeros.

So the 403 Forbidden message that I was getting was a little deceptive - 403 indicates that you have been denied access to a resource which is why I thought the scope may have been wrong - in my opinion this should have been a 400 : Bad Request as the request I had submitted had data that was invalid due to badly formatted data.