Page 1 of 1

Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 6:50 pm
by Bad Addy

I have been playing, to see how I can filter a REST query and then sort it by date. The latest date first.

code
url: 'https://api.appery.io/rest/1/db/collections/questions/',
dataType: 'json',
data: {
where: '{"sid":'+sid+'}',
sort: '{_createdAt}'
},
/code

I have tried different combinations, but none seem to sort the data, but i do not get an error either ?


Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 6:58 pm
by Kateryna Grynko

Hi,

Take a look at here please:
http://docs.appery.io/documentation/b...


Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 7:00 pm
by Bad Addy

Hi, I have read that, but it does not explain or demonstrate via REST API how to place both a WHERE and a SORT within the same request ?

Can it not be done ?


Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 8:55 pm
by Kateryna Grynko

You can use both two parameters. Just add them to a list of request parameters.


Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 9:04 pm
by Bad Addy

I thought I had done that above, but its not working. Is the syntax in my first post correct, when doing with it via API ?


Combine REST API where and sort ?

Posted: Wed Feb 12, 2014 9:06 pm
by Bad Addy

I have also tried this:

code
data: {
where: '{"sid":'+sid+'}, {"sort" : "_createdAt"}',
},
/code

And this does not work. If I wanted it to DESC I put a - after the = in CURL, but how do I managed this in API ?


Combine REST API where and sort ?

Posted: Thu Feb 13, 2014 12:26 am
by Igor

Sort should be as a separate request parameter.
pre
code
data: {
where: '{"sid":'+sid+'}
sort : "createdAt"
}
/code
/pre
if you need desc you should put "-" it before "createdAt"
pre
code
sort="-_createdAt"
/code
/pre

You could find correct CURL request here : http://docs.appery.io/documentation/b...


Combine REST API where and sort ?

Posted: Thu Feb 13, 2014 8:22 am
by Bad Addy

Thank you. So with your example above, sort : "-_createdAt" should work ?


Combine REST API where and sort ?

Posted: Thu Feb 13, 2014 5:06 pm
by Kateryna Grynko

Hi Addy,

Do you want to request Database using ajax? Try the following code please:precode
$.ajax({
type: 'GET',
beforeSend: function(request) {
request.setRequestHeader('X-Appery-Database-Id', 'xxxxxxxxxxxxxxxxxx');
request.setRequestHeader('Content-Type', 'application/json');
},
url: 'https://api.appery.io/rest/1/db/colle...',
data: {"where":'{"sid":"' + sid + '"}', "sort": "-_createdAt"},
success: function(res) {
console.log(res);
},
error: function(xhr, ajaxOptions, thrownError) {
console.log("Load error: " + xhr.status + " " + xhr.responseText);
}
});/code/pre