ServiceM8 - can I filter on more than one field

2019-07-25 00:14发布

问题:

I am looking into an integration with ServiceM8 and would like to use the $filter REST API to filter by more than one. Something like company_uuid and status. The ServiceM8 documentation give they following example but does not include any use for 'OR'/'AND' type logic.

"https://api.servicem8.com/api_1.0/job.json?%24filter=company_uuid%20eq%20'10420f98-7626-4405-bf43-043f1036623b'

回答1:

Update

You can still filter by most of the fields, but only one.

Exclude Completed Jobs:

  • The filter (in a whole URL for context) to exclude completed jobs is:
  • "https://api.servicem8.com/api_1.0/job.json?%24filter=status%20ne%20%22Completed%22"

  • Construction:

    %24 : $
    %20 : (space)
    %22 : "
    &   : &
    "   : "


It still cannot be used in conjunction with any other filter as far as I can see. Adding filters either causes a 500 error, or one filter will work and the other will be ignored, or it even sometimes gives a return response telling you not to bother:

  • {"errorCode":400,"message":"Advanced Record Filter Queries Not Supported"}

The reality is that at the time of writing this, that isn't possible. The functions on the Filtering page (Currently last revision July 1, 2014) are the absolute extent of it's functionality. Even then, it doesn't entirely work (For example, filtering for active status doesn't work at all).

Retrieving the whole end point is just as quick, but obviously depending on your application may have undesirable processing or bandwidth implications

Perhaps the halfway point would be selecting the most discriminative filter to retrieve your working data.

  • I.e. You can get all the jobs since 1st July 2016 using this filter:

  • %24filter=date%20gt%20%222016-07-01%22

That specific example actually includes jobs on the 1st July (There's no ge filter available), but it's guess work, as you don't really know how it's applying gt to your data as the documentation only gives an example of matching an exact uuid and a single numeric comparison.



标签: rest