kobotoolbox / kobocat

Our (backend) server for providing blank forms to Collect and Enketo and for receiving and storing submissions.
BSD 2-Clause "Simplified" License
117 stars 127 forks source link

Filtering data by date through API not working as documented #150

Open tinok opened 8 years ago

tinok commented 8 years ago

This is either a problem a problem of better documentation needed or the date filtering not working through the API due to a bug. Needs clarification.

From Ananda:

I can successfully run a query to directly match, say, a username and a value. For example, when I'm logged in to kobotoolbox.org and I run the following *in my browser address bar*, I get a subset of the data just for the specified username:

https://kc.kobotoolbox.org/api/v1/data/34150?query={%22username%22:%20%22kpec_joyful_reading_dev12%22}

However, if I'm going to use this in my app, I have to URLencode it, so the URL looks like this:

https://kc.kobotoolbox.org/api/v1/data/34150?query=%7B%22username%22:%20%22kpec_joyful_reading_dev12%22%7D

That's not a big deal. However, when it comes to a query requiring comparisons, I'm still running into problems getting this to work. I thought it might be a problem where I had to encode characters like ":" as well, but that doesn't seem to solve the problem. I've also tried changing "gt$" to "$gt" (from the mongoDB site documentation) but that also doesn't seem to resolve my issue. In all cases, the entire dataset is downloaded again.
onejgordon commented 8 years ago

I just ran into some issues with API queries as well. The Kobo documentation currently references two documents in the query section:

  1. One at mongodb - http://docs.mongodb.org/manual/reference/operator/query/
  2. One at formhub - https://github.com/modilabs/formhub/wiki/Formhub-Access-Points-(API)#api-parameters

However, these two links specify different date string formats, so I wonder if that's part of the issue?

onejgordon commented 8 years ago

Changing the comparator from gt$ to $gt fixed my problem. Would be great to get that fixed in the docs (https://kc.kobotoolbox.org/api/v1/data), as it's the only example given.