4

I am trying to figure out how I can make a request to the REST API for Parse that can accept a range against the createdAt column. I can issue the following constraint which works but when I try a compound query that tries to do a GT and a LT constraint I get a Bad Request error.

var requestParams = 'where={ "createdAt": { "$gt": { "__type": "Date", "iso": "' + startDate + '" } } } ';

Is this possible with the REST API?

2 Answers 2

9

I'm not quite sure in what format you are passing the startDate. The correct example to do such a thing is as follows.

curl
    -X GET
    -H "X-Parse-Application-Id: [APP_ID]"
    -H "X-Parse-REST-API-Key: [KEY]"
    -G --data-urlencode 'where={"createdAt":{"$gte":{ "__type": "Date", "iso": "2014-07-28T07:57:03.900Z" }}}'   
    https://api.parse.com/1/classes/[YOUR CLASS]

The example below shows how to do this using their Javascript SDK

Javascript query using greaterThan "createdAt"

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. Sorry, I should have been more clear. The date format is an ISO format and my where clause that I posted works. What I am trying to do now is perform a $gt and $lt on createdAt. By the looks of everything I have read, this is not possible with the REST API.
2

I think you can query a date range by combining multiple conditions for the date column rather than listing the column multiple times, which is what I tried and what I assume you tried. This worked for me:

{
  "createdAt": {
    "$gte": {
      "__type": "Date",
      "iso": "2019-01-15"
    },
    "$lte": {
      "__type": "Date",
      "iso": "2019-07-15"
    }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.