Xero API 401 unauthorized when retrieving Accounts API endpoint
Asked Answered
P

1

5

I am currently trying to retrieve the account details for the list of accounts using the following API endpoint : https://api.xero.com/api.xro/2.0/Accounts.

I have the following scopes included:
openid profile email accounting.transactions accounting.reports.read accounting.contacts.read.

I am however receiving the following error:

    [Title] => Unauthorized   
    [Status] => 401   
    [Detail] => AuthorizationUnsuccessful   

Thanks

Pentecostal answered 5/4, 2020 at 18:16 Comment(0)
V
6

The full list of scopes can be found here: https://developer.xero.com/documentation/oauth2/scopes

You'll find that accounting.settings and accounting.settings.read scopes give access to the Accounts endpoint

Visigoth answered 5/4, 2020 at 19:3 Comment(6)
Thanks, I did have a look at that page just happened to miss that scope.Pentecostal
I don't see xero.settings, only accounts.settings. accounts.settings.read is not giving me access to get /AccountsSpital
As of July 2022, it's accounting.settings.read. BTW, it seems that when connecting to a company owned by the same person as the OAuth app, the scopes are not necessary, which is very confusing. I didn't run into the 401 error myself, instead the client did when testing. For me the API returns the account data without the necessary scope.Saurian
@RafałG. Will this be due to the additive nature of the Xero API scopes? developer.xero.com/documentation/guides/oauth2/scopes/…Visigoth
@Visigoth Not really, the issue wasn't with needing some scopes before and then more scopes later. But my app works now, I'm just saying that the development process was glitchy.Saurian
Just to add to this, the Xero API Explorer (available once logged in via browser) shows you the required scopes for each specific request. Get Accounts currently requires scopes accounting.settings | accounting.settings.readBengurion

© 2022 - 2024 — McMap. All rights reserved.