Firebase Database REST get with orderBy value and equalTo

293 views
Skip to first unread message

Marcin Bak via StackOverflow

unread,
Feb 1, 2017, 12:51:05 PM2/1/17
to google-appengin...@googlegroups.com

I have a following architecture:

  • mobile client connecting to Google App Engine app (Java)
  • GAE makes gets some info from Firebase Database with a REST call

Because Firebase Admin SDK doesn't work well with GAE due to background threads, I decided to use Firebase REST API. All goes well when I update Firebase Database or get something from specific path but when I want to filter the data I encounter a problem.

When making cUrl request everything works great:

curl -X GET \
 -H 'Authorization: Bearer auth_token'  \
'https://my_project.firebaseio.com/items.json?orderBy="$value"&equalTo="some_string"'

But when doing exactly same request using HttpURLConnection or URLFetchService from java code in my GAE app I receive strange errors. At first those were urlencoding errors, so I had to change my url to something like this:

https://my_project.firebaseio.com/items.json?orderBy=%22%24value%22&equalTo=%22some_string%22

But even after that I receive 400 error codes with a following message:

{ "error" : "orderBy must be defined when other query parameters are defined" }

My request code looks like this:

URL url = URL(urlString);
HTTPRequest request = HTTPRequest(url, HTTPMethod.GET, opts)
request.addHeader(HTTPHeader(AUTH_HEADER, "Bearer " + accessToken));
HTTPResponse responseRaw = service.fetch(request);

Any idea what I am doing wrong?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41986194/firebase-database-rest-get-with-orderby-value-and-equalto

Marcin Bak via StackOverflow

unread,
Feb 1, 2017, 3:01:05 PM2/1/17
to google-appengin...@googlegroups.com

I have a following architecture:

  • mobile client connecting to Google App Engine app (Java)
  • GAE makes gets some info from Firebase Database with a REST call

Because Firebase Admin SDK doesn't work well with GAE due to background threads, I decided to use Firebase REST API. All goes well when I update Firebase Database or get something from specific path but when I want to filter the data I encounter a problem.

When making cUrl request everything works great:

curl -X GET \
 -H 'Authorization: Bearer auth_token'  \
'https://my_project.firebaseio.com/items.json?orderBy="$value"&equalTo="some_string"'

But when doing exactly same request using HttpURLConnection or URLFetchService from java code in my GAE app I receive strange errors. At first those were urlencoding errors, so I had to change my url to something like this:

https://my_project.firebaseio.com/items.json?orderBy=%22%24value%22&equalTo=%22some_string%22

But even after that I receive 400 error codes with a following message:

{ "error" : "orderBy must be defined when other query parameters are defined" }

My request code looks like this:

URL url = URL(urlString);
HTTPRequest request = HTTPRequest(url, HTTPMethod.GET, opts)
request.addHeader(HTTPHeader(AUTH_HEADER, "Bearer " + accessToken));
HTTPResponse responseRaw = service.fetch(request);

I tried to use different values as urlString (simply assigning string to a variable) to no vail:

String urlString = "https://my_project.firebaseio.com/items.json?orderBy=%22%24value%22&equalTo=%22some_string%22";

String urlString = "https://my_project.firebaseio.com/items.json?orderBy=%22$value%22&equalTo=%22some_string%22";

String urlString = "https://my_project.firebaseio.com/items.json?orderBy=\"$value\"&equalTo=\"some_string\"";

The third value caused an exception and no request was sent.

Marcin Bak via StackOverflow

unread,
Feb 1, 2017, 4:51:08 PM2/1/17
to google-appengin...@googlegroups.com

The third value caused an exception and no request was sent. What's more removing equalTo parameter makes the request work, I get 200 and json in response:

String urlString = "https://my_project.firebaseio.com/items.json?orderBy=%22$value%22";

Marcin Bak via StackOverflow

unread,
Feb 2, 2017, 4:57:05 AM2/2/17
to google-appengin...@googlegroups.com

It was painful to find but I set up a proxy to see outgoing request from the local app engine server, and it showed some no-width space unicode characters that caused the problem.

orderBy\u200c\u200b=

After removing those two characters everything works as it should.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/41986194/firebase-database-rest-get-with-orderby-value-and-equalto/41998914#41998914
Reply all
Reply to author
Forward
0 new messages