Closed (fixed)
Project:
Xero API
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Aug 2018 at 03:32 UTC
Updated:
3 Sep 2018 at 12:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
johnpitcairn commentedThe response is
400 Bad Request. Looks like any non-boolean condition on optional Xero fields must be preceded by a null guard condition.FirstName!=null&&FirstName.Contains("J")I don't think there is currently any way to add such a condition via XeroQuery and obtain the correct URL format, is there? We want
nullwithout quotes.Comment #3
johnpitcairn commentedComment #4
johnpitcairn commentedAfter adding NOT NULL as an operator and converting that to
[fieldname]!=null, the resulting query still doesn't work because query conditions are currently concatenated by a space. This patch:Getting OR groups working is perhaps a followup issue?
Comment #5
johnpitcairn commentedComment #6
johnpitcairn commentedComment #7
mradcliffeThank you for the patch.
I went back to look at the old PHP-Xero library, and it is pretty much doing this so this is a regression from 7.x-1.x. It also only supported &&.
2. XeroQuery has the
addOperatormethod, but no real examples around it, which basically just tacks on AND (or OR). Do you think this is a bit too cumbersome as an api user?This seems to work fine if we add the NOT NULL portion.
(Edit: I think that doing 1.1 above and 3 below would be much easier to use).
3. It might be possible to take a look at the definition and auto-add the not null, but that could break existing uses so probably would need to add an optional parameter onto addCondition (or duplicate the method). Maybe
checkNull = FALSE. What do you think?I think that complex condition groups would be nice, but yes, agreed that should be a follow-up.
Comment #8
johnpitcairn commentedHa, I totally missed the
addOperatormethod. Yes, imploding withANDdoes error if there is only one condition.Personally I don't see a need to auto-concatenate conditions using
ANDif operators have not been explicitly added. Let's just document theaddOperatormethod.Since Xero supports both
==nulland!=nullconditions, I think it might be reasonable to explicitly support both those asNULLandNOT NULLoperations? I can see a case for wanting to find all contacts where the email field is empty, for example.I also think it's fine for the developer to be responsible for adding the null field guard condition, let's make that possible and documented (which has the benefit of also providing an
addOperatorexample).Then the resulting query construction code is very clear and doesn't depend on any magic behavior in XeroQuery.
Comment #9
johnpitcairn commentedThis patch:
Adds
NULLandNOT NULLoperations, mapped to==nulland!=nullin the query string.Updates README.md to document the addOperator() method, comparison operations, and provide examples with comparison operations, multiple conditions and a null field guard.
Comment #10
mradcliffeThis looks good.
I expanded the unit test coverage for the new conditions.
Comment #11
johnpitcairn commentedComment #12
johnpitcairn commentedLooks good to me. Mostly my patch, so I shouldn't RTBC?
Comment #14
mradcliffeOkay, I think that's fine. Thank you.
Committed.