I have a following architecture:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With