Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Combine REST API where and sort ?

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 ?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Combine REST API where and sort ?

Hi,

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

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Combine REST API where and sort ?

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 ?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Combine REST API where and sort ?

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

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Combine REST API where and sort ?

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 ?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Combine REST API where and sort ?

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 ?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Combine REST API where and sort ?

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...

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Combine REST API where and sort ?

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Combine REST API where and sort ?

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

Return to “Issues”