XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
87 stars 64 forks source link

[Major] Query Parse issue for Accounting API #307

Closed ksuchan closed 1 year ago

ksuchan commented 1 year ago

There seems to be an issue since version ~2.10 of the SDK at least on the accounting API getBankTransactions endpoint. When trying to retrieve transactions with a where query of sort: "(Date >= DateTime.Parse("2022-06-01T00:00:00") AND Date <= DateTime.Parse("2022-11-30T00:00:00")) AND status!="DELETED" AND ()"

the underlying Guzzle lib does encode the URL fully resulting in a query like like

where=%28Date%20%3E%3D%20DateTime.Parse%28%222022-06-01T00%3A00%3A00%22%29%20AND%20Date%20%3C%3D%20DateTime.Parse%28%222022-11-30T00%3A00%3A00%22%29%29%20%20AND%20status%21%3D%22DELETED%22%20AND%20%28%29&page=0

the expected behaviour so far was a result with data from xero however now Xero returns a 400 error:

Client error: GET https://api.xero.com/api.xro/2.0/BankTransactions?where=(Date%20%3E=%20DateTime.Parse(%222022-06-01T00:00:00%22)%20AND%20Date%20%3C=%20DateTime.Parse(%222022-11-30T00:00:00%22))%20%20AND%20status!=%22DELETED%22%20AND%20()&page=0 resulted in a 400 Bad Request response: { "ErrorNumber": 16, "Type": "QueryParseException", "Message": "Expression expected" }

Now going through the entire code path in this particular request it is obvious that the encoding is a result of Guzzle PSR7 logic which in turn suggests that the issue may lay on the API side where URL queries are not decoded properly.

pumpkinball commented 1 year ago

Hi @ksuchan thanks for your query. I believe the error you are getting 'Expression expected' is due to the " AND ()" you have at the end of your query, if remove that, it should work. You can check your requests with queries anytime via our API Explorer.

ksuchan commented 1 year ago

Oh my... thanks for noticing that @pumpkinball

I do feel like an eejit now hah.

And it does work without these :D