Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Database REST get with orderBy value and equalTo

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

Any idea what I am doing wrong?

like image 640
Marcin Bak Avatar asked Feb 01 '17 17:02

Marcin Bak


1 Answers

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.

like image 167
Marcin Bak Avatar answered Oct 02 '22 04:10

Marcin Bak