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

AccountingApi.GetTaxRatesAsync with no parameters #455

Closed rkhe closed 1 year ago

rkhe commented 1 year ago

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

Describe the bug AccountingApi.GetTaxRatesAsync endpoint returns null when passing null or no parameters. Not sure but seems like it happens when the Tax Rate has Box number(s) on F5 return option enabled or available. Web-based API Explorer doesn't seem to have this issue.

To Reproduce Steps to reproduce the behavior:

  1. Execute Task.Run(() => AccountingApi.GetTaxRatesAsync(token, tenantId)).Result;

Expected behavior Expecting a list of all Tax Rates under the system.

Screenshots Short Vid: https://www.screencast.com/t/rWExpKEeaPd Screenshot: https://www.screencast.com/t/OBzSJrrE1

JRising-Xero commented 1 year ago

Hi @rkhe, Your tenantId may be invalid which is causing the task to return null. Usually, an invalid authentication exception will be returned, however, in this case it seems the way you are calling the endpoint with Task.Run() is causing the exception to be ignored and null to just be return.

Could you recall the endpoint in your code using the following structure and see if you get a validation exception:

public async Task<TaxRates> GetTaxRates()
{
    var accountingApi = new AccountingApi();
    var taxRates = await accountingApi.GetTaxRatesAsync(AccessToken, TenantId);

    return taxRates;
}

Call the method like:

var taxRates = await GetTaxRates();

I would also recommend running the .NET sample app and click on the Get Tax Rates button under Accounting section. Check if your tax rate appears, if it works here, I would check how the authentication code is done here and compare to how you are doing it in your solution.

Hope this helps.

rkhe commented 1 year ago

HI @JRising-Xero ,

Thank you for taking the time on this.

The code I'm working on is a very old one and Async-Await programming isn't implemented on this yet so I don't want to refactor anything as much as possible unless it needed to.

I have another short video showing that the same creds works in getting Accounts but not TaxRates. https://www.screencast.com/t/Qt0JpcqR4gR4 Could this be a authorization issue instead of authentication?

Still trying to make the .NET sample app work to for now.

rkhe commented 1 year ago

Hi @JRising-Xero ,

Here's another video showing getting Tax Rates fails now using .Net Standard Starter App. https://www.screencast.com/t/0mCI6MUmL

Hope this helps with the debugging. I appreciate your hard work.

JRising-Xero commented 1 year ago

Hey @rkhe, Thanks for the extra videos, it doesn't look like a tenant issue. This behaviour is definitely odd. You mentioned that the tax rates returned correctly from the api explorer, could you paste the json response here? In addition, if you could also provide your client id we can look through the api logs to see if any odd behaviour is occurring.

Thanks.

rkhe commented 1 year ago

Hello @JRising-Xero

Attached is the json response from API-Explorer. Xero-Tenant-Id: e9e789d8-bc2d-4fc0-bec8-a6d970fb27a6 JSON: xero-tax-rates-response.json.txt

JRising-Xero commented 1 year ago

Hi @rkhe, Looking at the api logs I don't see any unusual behaviour, the api is returning correct responses. Would you be able to call the GetTaxRates with HttpInfo, i.e:

var taxRates = await Api.GetTaxRatesAsyncWithHttpInfo(XeroToken.AccessToken, TenantId);

This will give us some additional details, the important one being content, this is the http response which the SDK uses to parse the data to the appropriate model. With this we can determine whether the SDK is receiving a valid json response.

image

rkhe commented 1 year ago

Hi @JRising-Xero ,

There seems to be an error (ErrorText): "Error converting value "BADDEBTRELIEF" to type 'Xero.NetStandard.OAuth2.Model.Accounting.TaxRate+ReportTaxTypeEnum'. Path 'TaxRates[0].ReportTaxType', line 10, position 38." Screenshot: https://www.screencast.com/t/W6zTQ34HWJ

Content JSON: xero-tax-rates-response-using-HttpInfo.json.txt

It looks like the culprit.

JRising-Xero commented 1 year ago

Hey @rkhe, Ah that's exactly what we needed. Looks like the .NET SDK version you are using doesn't support BADDEBTRELIEF, see here. You'll need to upgrade to at least version 3.25.0, see release notes here.

Hope this helps.

rkhe commented 1 year ago

@JRising-Xero

I've upgraded the version to 3.31.0 for the .Net Standard Starter App and it's now working fine. However, I'm still in a pinch with the old project since throws a lot of dependency packages that needs to be updated and I ran to some non-Xero related affected issues. Oh well, at least I'm on the right path on this.

Thank you very much, I appreciate your help.