Invalid Argument with UrlFetch

Invalid Argument is coming because you are sending invalid characters in the URL parameter. You should encode the parameters first.

I modified your code and tried to run. But it still failed because of invaliD API key which is obvious. You may try this code with a valid API key.

//start and end are JS date objects
  MONGO_LAB_URLS = 'https://api.mongolab.com/api/1/databases/abcd/collections/efgh?apiKey=XXXXXXXXXXXXXXXX&q=';
  var start = 'Thu Dec 06 00:00:00 PST 2012';
  var end = 'Thu Dec 06 23:59:59 PST 2012';

  var query = { created_on : {'$gte': start, '$lt' : end} };
  var url = MONGO_LAB_URLS + encodeURIComponent(Utilities.jsonStringify(query));  
  Logger.log("Query URL : " + url);  
  var response = UrlFetchApp.fetch(url);
  Logger.log(response);

Response which I am getting is

Request failed for https://api.mongolab.com/api/1/databases/abcd/collections/efgh?apiKey=XXXXXXXXXXXXXXXX&q=%7B%22created_on%22%3A%7B%22%24gte%22%3A%22Thu%20Dec%2006%2000%3A00%3A00%20PST%202012%22%2C%22%24lt%22%3A%22Thu%20Dec%2006%2023%3A59%3A59%20PST%202012%22%7D%7D returned code 400. Server response: { "message" : "Please provide a valid API key."}

This worked for me, basically just add this line:

var urlEncoded = encodeURI(url);

and then call

UrlFetchApp.fetch(urlEncoded);