Search code examples
c#.net-standardxero-api

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


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?


Solution

  • 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