XeroAPI / Xero-NetStandard

A wrapper of the Xero API in the .NetStandard 2.0 framework. Supports Accounting, Payroll AU/US, and Files
MIT License
120 stars 119 forks source link

Error when using GetReportBalanceSheetAsync in a web app: Object reference not set to an instance of an object. #431

Open rakhmetov75 opened 1 year ago

rakhmetov75 commented 1 year ago

SDK you're using (please complete the following information):

Describe the bug A clear and concise description of what the bug is. When I call GetReportBalanceSheetAsync in a console app, all works fine. When I call the same method in a web app I get an error message: Object reference not set to an instance of an object. Other similar reports like the one for Profit and Loss fail the same way. I can't even use try {} catch {} to catch the exception, the app crashes.

I worked with API support team and confirmed it is not an API issue, as the report gets returned fine, but the application crashed inside the SDK methods.

To Reproduce Steps to reproduce the behavior: Create a web app project in VS C# (.Net Framework 4.7.2). Call GetReportBalanceSheetAsync method. Xero.NetStandard.OAuth2.Model.Accounting.ReportWithRows pal = await apiInstance.GetReportBalanceSheetAsync(accessToken, xeroTenantId, startDate, 1, timeFrame, null, null, true, false).ConfigureAwait(false);
fullReport = JsonSerializer.Serialize(pal);

Expected behavior A clear and concise description of what you expected to happen. The call should return the report to a variable

Screenshots If applicable, add screenshots to help explain your problem. Not much on the screenshot, just an error: Object reference not set to an instance of an object. Additional context Add any other context about the problem here.

Relebohile3369 commented 1 year ago

Hi,

I downloaded the code, and everything else works fine except for Finance - Balance sheet, Profit and loss etc.

An unhandled exception occurred while processing the request. ApiException: Xero API error calling GetFinancialStatementBalanceSheet: {"Type":null,"Title":"Unauthorized","Status":401,"Detail":"AuthorizationUnsuccessful","Instance":"889b771f-be89-4bf8-9424-6642f6cf82ff","Extensions":{}} Xero.NetStandard.OAuth2.Api.FinanceApi.GetFinancialStatementBalanceSheetAsyncWithHttpInfo(string accessToken, string xeroTenantId, string balanceDate)

Here are screenshots of the error message and my code in VS. https://drive.google.com/drive/folders/1Qsrxc-rBh4I2DZ95O3aVyxBK_b4tOvCl?usp=sharing

Screenshot 2022-08-14 121923

Screenshot 2022-08-14 122216

rlayhbrian commented 1 year ago

Hello everyone, The finance and bankfeed APIs actually require a scope grant from Xero for their uses as they are closed APIs That's probably the reason why it (or they) is throwing those exceptions and errors

rakhmetov75 commented 1 year ago

Hi Brian, I spent a good amount of time with the API team and used various debuggers. In my case the API was returning the report and we found it was breaking on SDK level. The scopes had been setup. Besides, the same works in a console application, which shares the same project with my web app. It breaks only for the web app.

Sallyhornet commented 1 year ago

I checked our logs and the instance id 47f6f754-b6b2-4ea4-99e3-b4a160519f83 and instance id 889b771f-be89-4bf8-9424-6642f6cf82ff have the error message: No scope match, Required scopes: finance.statements.read.

Please note, you can get the P&L and balance sheet from the reports endpoint in the accounting API. This doesn't need the finance scopes, which are restricted, so maybe this was how you got the reports using the console application.

If this is not the case, please can you send details of the issue to api@xero.com and include the client id of the console app that worked and the date and time of the most recent call

rakhmetov75 commented 1 year ago

Hi Sally,

These are the scopes I was using: accounting.reports.read accounting.settings accounting.settings.read

Both console app and web app using the same tokens saved in a database. I would run the console app and all entities would work (we have over 60). I run the web app next and it fails with the error mentioned in my first post.

The way I setup those scopes was via xoauth setup:

Once I get the tokens I use Insomnia client to get tenant id. After that I put all the tokens, tenant ids, client ids, client secrets, etc. into a database used by both console app and web app. Console app works fine, web app fails.
I've worked with the API team and they confirmed that the API was returning the balance sheet report with no problem when I was running the web app, this is what they said: "We can see the API call on our logs, and from our side it would appear that the call completed successfully." I was talking to Robin and emailing to api@support.xero.com. Using the debugger I found it was crashing inside the GetReportBalanceSheetAsync method, which is part of SDK. They actually checked the logs and I could see the json file inside the GetReportBalanceSheetAsync method identical to the one returned in console app. I would assume if the scope were wrong, the API would not return the value with the report.

Abhisha1 commented 1 year ago

Hey @rakhmetov75 Are you still facing this issue?

rakhmetov75 commented 1 year ago

Hi,

Yes, I do. Sorry for the delay in replying, I have been away.

Regards, Roustam.


From: Abhisha @.> Sent: Tuesday, 20 September 2022 1:16 PM To: XeroAPI/Xero-NetStandard @.> Cc: rakhmetov75 @.>; Mention @.> Subject: Re: [XeroAPI/Xero-NetStandard] Error when using GetReportBalanceSheetAsync in a web app: Object reference not set to an instance of an object. (Issue #431)

Hey @rakhmetov75https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frakhmetov75&data=05%7C01%7C%7Cf5a539d329574c5e57f408da9ab68167%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637992405899224246%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=zBmY%2BmsNBUSrxztk6asQHIY%2FsyYLHIXcwq5M%2BXtnmqg%3D&reserved=0 Are you still facing this issue?

— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FXeroAPI%2FXero-NetStandard%2Fissues%2F431%23issuecomment-1251784962&data=05%7C01%7C%7Cf5a539d329574c5e57f408da9ab68167%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637992405899224246%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=QCnSKW5jNOacLP55NJO8CoeRBI6HamzFeNmkseVrbcA%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMFO57URIZMKZOK4WLXOIW3V7EUAVANCNFSM54UIZI5Q&data=05%7C01%7C%7Cf5a539d329574c5e57f408da9ab68167%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637992405899224246%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=C9pduPIeJdzX6uesz8A6smu80%2FEAFkuClt73QCg4dvo%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.***>

Abhisha1 commented 1 year ago

Hi @rakhmetov75 I was able to replicate your error and it was resolved using the scope update Sally suggested.

Please add the scope finance.statements.read to your application and then reconnect (revoke and reconnect) so that the scopes update. This should solve the problem.

When connecting it should have the last line (view financial statements) image