xero-php
xero-php copied to clipboard
Purchase Order Where Clause not applying
When using the Purchase Order endpoint, setting the where status does not apply to the request.
$purchaseOrders = $xero->load(PurchaseOrder::class)
->where('Status', PurchaseOrder::PURCHASE_ORDER_STATUS_AUTHORISED)
->where('PurchaseOrderNumber', 'PO-0002')
->execute();
The query still returns invoices outside of the above parameters, including the status
Can you try this again please? I also had clients with the set parameters not being followed, and some of them said that other products using the Xero API were also returning things they shouldn't have, but it appears to have resolved itself.
Just tried again and the same result.
I'm having the same issue. The following code should only be displaying one result and seems to be displaying all of them:
$purchase_orders = $xero->load(PurchaseOrder::class)
->where('Date >= DateTime(2020, 09, 16)')
->execute();
Note: I'm using the latest stable release 2.2.1
@matthewknill What happens if you make this request in the API Previewer?
Sorry for taking quite a while to respond. Yes it seems to be working fine from the API Previewer (from my knowledge at least - I hadn't ever used the API Previewer before).
FYI the Xero API PurchaseOrders endpoint doesn't support a where clause, unlike the Invoices endpoint.
See https://community.xero.com/developer/discussion/14123353
@matthewknill this suggests it can't be done via the API, closing for now.
It is mentioned that DateFrom, DateTo and Status are supported. How can I do this if not using the above (these are in fact all I need)?
@matthewknill OK, maybe it needs to be a parameter rather than a where? i.e. using ->addParameter()
to the request
Hmm seems like ->addParameter()
function does not exist in the library... Am I doing it right (obviously would need to add parameter):
/** @var PurchaseOrder[] $purchase_orders */
$purchase_orders = $xero->load(PurchaseOrder::class)
->addParameter()
->execute();
@matthewknill have a look inside the $xero->load()
method, that's how the request is actually constructed.
Holy moly. Thanks for continuing to look into this one. I've been developing a feature in an app that updates line items within a purchase order under certain conditions. It's a pretty curly feature so I've been working on it for weeks. And it's just become clear that Xero appear to disallow filtering/finding on this endpoint where other endpoints are fine with it.
Should we possibly pop an exception within \XeroPHP\Remote\Query::addWhere
to pick out if $this->from_class
is PurchaseOrder
, explaining that filtering on this endpoint is currently disallowed? I'm fairly sure it would have saved me this heartache.. :)