Filtering API query results by date

Well. I’ve been digging some more, and in the interests of sharing my now working results, here is what I’ve found.

  1. There is an outstanding documentation bug reported well over two years ago at https://github.com/kobotoolbox/kobocat/issues/150, such that the operators are actually $gt rather than gt$, etc.

  2. The date field shown in the example is a red-herring. Rather, the field to be compared must exist in the dataset. I’ve been using _submission_time.

  3. The query must be URL-encoded. Here is an example that works for me with the curl command-line tool

     curl -s -G --user "$username:$password" --data-urlencode query='{"_submission_time":{"$gt":"2019-02-27"}}' https://kc.kobotoolbox.org/api/v1/data/12345
    

    The date/time value can be either a date (as in the example here) or a more complete date/time such as 2019-02-17T17:00:00+0000 to indicate 5pm UTC on 17th February 2019.

2 Likes