In XeroQuery.php, a POST request (update) is always changed to PUT if $query->uuid is not set.
Why is this so? The POST example in the documentation makes no mention of requiring a uuid.
The comment for $uuid in XeroQuery.php states that it is "The xero UUID to use for a quick filter in get queries." XeroQuery::setId() states "Useful only in get method". OK then - but in XeroQuery::execute(), we have this:
// Change to PUT if UUID is not set for a post.
if ($this->method === 'post' && !$this->uuid) {
$this->setMethod('put');
}So while it may only be "useful" for GET queries, not setting it has other consequences.
It looks to be impossible to update an existing Xero item via POST using the example code. The request will always be made via PUT and will fail because a Xero item with those distinguishing characteristics already exists (Contact Name, for example).
Issue fork xero-3227619
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
johnpitcairn commentedComment #3
johnpitcairn commentedSo what is currently needed if you want to update a list of existing contacts is something like:
Correct?
That's still a bit of a WTF moment, because the UUID you are giving it is only one of potentially many in the contact list. It makes little sense.
We could just update the README to include the above, but first I think it might be better to examine why that POST/PUT switch is there in the first place. Is it just a hangover from some outdated implementation? Can/should it be removed? If not, a more verbose comment for that and the
$uuidproperty/method is needed, as well as a README update.Comment #4
johnpitcairn commentedComment #5
johnpitcairn commentedComment #6
jonathanshawI think you're right.
The doc for setId say it's only relevant to get, and it is definitely used there.
Xero docs say that post can create or update, put is create only.
If we want to have this put/post switch, it should probably be linked to an explicit flag "canCreate" not this implicit uuid logic that only makes sense when working with a single item.
Comment #8
jonathanshawI suggest a simple removal.
Comment #9
johnpitcairn commentedI agree. If anything is setting the uuid for post queries, it won't cause any issues.
I can't imagine a scenario where you'd be relying on POST getting silently switched to PUT?
Comment #12
mradcliffe