I am trying to run a MongoLab (REST based access to MongoDB) query via Google Apps Script. The URL is generated from the logger is shown below
https://api.mongolab.com/api/1/databases/abcd/collections/efgh?apiKey=XXXXXXXXXXXXXXXX&q={"created_on":{"$gte":"Thu Dec 06 00:00:00 PST 2012","$lt":"Thu Dec 06 23:59:59 PST 2012"}}
When I type this in the browser, it works and gets me the response I am looking for. But running it via UrlFetchApp gives an "Invalid Argument" error. I see there are several posts along the same lines but didn't find an answer that worked for me. The Javascript code is as follows
//start and end are JS date objects
var query = { created_on : {'$gte': start, '$lt' : end} };
var url = MONGO_LAB_URLS.MAIN + "&q=" + Utilities.jsonStringify(query);
Logger.log("Query URL : " + url);
var response = UrlFetchApp.fetch(url);
I tried encodeURIComponent, but it did not work - may be I was doing it incorrectly. Any suggestions as how I could overcome this issue?
Thanks.