calcinai / xero-php

A php library for the Xero API, with a cleaner OAuth interface and ORM-like abstraction.
MIT License
359 stars 262 forks source link

Add in the PUT type to create new TaxRates #872

Closed mogilvie closed 1 year ago

mogilvie commented 1 year ago

Was not able to create new tax types (although this used to work sometime ago) Added in the PUT type as per the documentation and now my original code works again.

API link here. https://developer.xero.com/documentation/api/accounting/taxrates

mogilvie commented 1 year ago

Note that the PUT method was removed in https://github.com/calcinai/xero-php/commit/cbd03cfd268e30735b1246b62d9639fbab1a9776 because the POST is supposed to work for creating tax rates.

However, when you post the same content to Xero it tries to modify an existing tax rate, even when the names don't match. And if the number of TaxComponents in the existing (but differently named) TaxRate don't match the submitted TaxComponent count, then you get the error below.

POST not working: image

The Xero API is finding the first available existing TaxRate, then comparing the number of TaxComponents and firing the error.

As a test, I also posted a new tax rate without tax components, and the POST overwrote the name of an existing (and unrelated) TaxRate.

Using PUT works: image

calcinai commented 1 year ago

LGTM, this kind of thing has been really inconsistent in the API over the years