Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:17:24+00:00 2026-06-15T15:17:24+00:00

I am trying to run a MongoLab (REST based access to MongoDB) query via

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:17:26+00:00Added an answer on June 15, 2026 at 3:17 pm

    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."}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to run a MySQL script via Python and it keeps giving me errors.
I am trying run a program from a qmake .pro file which modifies the
I trying to run a Perl script to read an YAML file, but I
Trying to run some sql in a pl/sql procedure. Select field from schema.view; I
Trying to run a script on the page load, where if a className is
Trying to run z3c.form.testing based code on Plone 4.1 and getting this exception Traceback
Trying to run gvim 7.3 from the working directory (project location) seems impossible-- it
Trying to run FireFox through apache (php script) I recieve the following error No
Trying to run this little perl program from parsCit: parsCit-client.pl e1.txt Too late for
I am trying to run the C libraries from SIGAR API. In the include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.