XeroAPI/xero-ruby-oauth2-app

Unauthorized Error trying to test Finance scope

sbecka opened this issue · 2 comments

Hello, I was able to get this sample app up locally and connected it to my Demo Company in my Xero account. I was also able to get responses from other API endpoints like the accounts to return data without any issues.

However, I'm getting an unauthorized error when trying to test the Finance API endpoints and some other endpoints. I'm not sure if I set up the scopes in my .env file properly. I don't fully understand the scopes syntax yet and how additive it needs to be. Whenever I changed the scopes variable, I stopped and restarted my local server. In addition, when I get this error, I am able to go back and test the other endpoints and still get data to return from them. The only code changes I made was adding the .env file and setting up my environment variables in it.

Scopes in my .env file looks like this right now:
SCOPES="openid profile email accounting.settings accounting.reports.read accounting.journals.read accounting.contacts accounting.attachments accounting.transactions assets assets.read projects projects.read finance finance.statements.read finance.statements.trialbalance.read offline_access"

Here is the error outputs when trying to access trial balance:
{"Type":null,"Title":"Unauthorized","Status":401,"Detail":"AuthorizationUnsuccessful","Instance":"609f6167-0597-4dea-bcab-02a27a3a2bf5","Extensions":{}}

XeroRuby::ApiError - Error message: the server returns an error HTTP status code: 401 Response headers: {"content-type"=>"application/json", "content-length"=>"152", "server"=>"nginx", "www-authenticate"=>"insufficient_scope", "xero-correlation-id"=>"609f6167-0597-4dea-bcab-02a27a3a2bf5", "x-appminlimit-remaining"=>"9999", "expires"=>"Fri, 10 Jun 2022 20:43:10 GMT", "cache-control"=>"max-age=0, no-cache, no-store", "pragma"=>"no-cache", "date"=>"Fri, 10 Jun 2022 20:43:10 GMT", "connection"=>"keep-alive", "x-client-tls-ver"=>"tls1.3"} Response body: {"Type":null,"Title":"Unauthorized","Status":401,"Detail":"AuthorizationUnsuccessful","Instance":"609f6167-0597-4dea-bcab-02a27a3a2bf5","Extensions":{}}: app/controllers/finances_controller.rb:41:in 'financial_statement_trial_balance'

Screen Shot 2022-06-10 at 5 19 27 PM

Screen Shot 2022-06-10 at 5 16 11 PM

The finance API is restricted is only available for Financial Institutions that have a formal relationship with Xero.
If you want to request a balance sheet report you can use the reports endpoint instead, https://developer.xero.com/documentation/api/accounting/reports/#balance-sheet.

If you are a financial institution, you can apply for access to the finance API here https://www.xero.com/us/partner-programs/financialweb/

Thank you! Sorry I was not able to find the trial balance or balance sheet reports on the left dropdown menu of this sample app under Accounting and then Reports. I could only see 'Get All', 'Report (Profit &. Loss)', and 'Report (Bank Summary)' being listed under the Reports section of the menu. Then I tried to look elsewhere and could only see them being listed under the Finance -> Financial Reports section and did not understand they were different.