Greg5988649
Posts: 0
Joined: Wed Jun 26, 2013 2:03 am

How to use the "Where" clause in a distinct query

Hi,

I'm building an app with nested lists (on separate pages). Each list needs to be a distinct list, restricted further by the items chosen in the earlier lists.

I can achieve a distinct list via the REST service but can't seem to get the "Where" clause working - either with a defined value or a local storage variable. It works when testing the service but not with mapping. I assume the answer lies with JavaScript but I can't figure it out.

My DB collection has the fields, OriginPort, DestinationPort, CntrType, Rate.
Here is the process flow:
1) I list distinct OriginPort.
2) The user clicks an item on the list and a local storage variable, originVB, is created.
3) Navigate to next page/list where I list distinct DestinationPort where OriginPort = originVB. This is where it fails and nothing is listed.

The local storage variable is definitely being set. The JS console in Chrome is showing "400 Bad Request".

I'm using the following JS in the "Where" request parameter:
var value1 = localStorage.getItem('originVB');
return '{"OriginPort":"'+value1+'"}';

Please help!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

How to use the "Where" clause in a distinct query

Use Chrome Dev. Tools Network tab to see the actual request that's being sent.

Greg5988649
Posts: 0
Joined: Wed Jun 26, 2013 2:03 am

How to use the "Where" clause in a distinct query

Hi Max

Thanks for your reply. Here is the request. It all seems OK to me but hopefully your trained eye will pick something obvious up:

Request URL:https://api.appery.io/rest/1/db/colle...
Request Method:POST
Status Code:400 Bad Request
Request Headersview source
Accept:application/json, text/javascript, /; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:38
Content-Type:application/json
Host:api.appery.io
Origin:http://appery.io
Referer:http://appery.io/app/view/eb22e6f3-e6...
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Appery-Database-Id:51a28f54e4b00afed5f89e41
Request Payloadview source
{where:{"OriginPort":"Bluff"}}
where: "{"OriginPort":"Bluff"}"
Response Headersview source
Access-Control-Allow-Origin:http://appery.io
Connection:keep-alive
Content-Type:application/json
Date:Wed, 26 Jun 2013 04:15:39 GMT
Server:nginx
Transfer-Encoding:chunked

Greg5988649
Posts: 0
Joined: Wed Jun 26, 2013 2:03 am

How to use the "Where" clause in a distinct query

Further to the above, note that "Bluff" was selected from the first list and appears to have come through correctly to the JS from the local storage variable.

Anton Artyukh5836028
Posts: 0
Joined: Wed May 08, 2013 12:57 pm

How to use the "Where" clause in a distinct query

Hi Greg,

I don't see in your request headers X-Appery-Session-Token.
Do you have any authorization actions?

Greg5988649
Posts: 0
Joined: Wed Jun 26, 2013 2:03 am

How to use the "Where" clause in a distinct query

Hi Anton

I wasn't but have now included a login page and session token:

Request URL:https://api.appery.io/rest/1/db/colle...
Request Method:POST
Status Code:400 Bad Request
Request Headersview source
Accept:application/json, text/javascript, /; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:39
Content-Type:application/json
Host:api.appery.io
Origin:http://appery.io
Referer:http://appery.io/app/view/eb22e6f3-e6...
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
X-Appery-Database-Id:51a28f54e4b00afed5f89e41
X-Appery-Session-Token:4f2df0c9-afc6-4712-be76-14042ba358dc
Request Payloadview source
{where:{"OriginPort":"Nelson"}}
where: "{"OriginPort":"Nelson"}"
Response Headersview source
Access-Control-Allow-Origin:http://appery.io
Connection:keep-alive
Content-Type:application/json
Date:Wed, 26 Jun 2013 22:49:26 GMT
Server:nginx
Transfer-Encoding:chunked

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to use the "Where" clause in a distinct query

Hello! There was an error in docs. Please use POST method instead of GET. Also replace code codevar value1 = localStorage.getItem('originVB');
return '{"OriginPort":"'+value1+'"}'; /code with the following codevar value1 = localStorage.getItem('originVB');
return {"OriginPort": value1 }; //return object, not a string/code

Greg5988649
Posts: 0
Joined: Wed Jun 26, 2013 2:03 am

How to use the "Where" clause in a distinct query

Excellent! Thanks Marina.
I was already using the POST method but it was the error in the JS that you pointed out. Such a silly mistake but thanks so much for finding it :-)

EJLD
Posts: 0
Joined: Sun Jun 08, 2014 11:03 pm

How to use the "Where" clause in a distinct query

Hi There, I am facing the same kind of issue:
. the distinct query is set on the field "receiver",
. and I would like to filter using a criteria from a different field, the "sender".
I am testing in where : {"sender":"EJLD"}
so far, it is not taken into account.
still I get the same set of data as response.
Any advice ?
Thk you in advance,
Eric

Return to “Issues”