javascriptgoogle-sheetsgoogle-apps-scriptredash

Redash to Google Sheets - Date parameters not being registered


I'm trying to write a script to send redash data to google sheets. I've updated the script to use payload parameter instead of body and now it's showing me the following error:

{"message": "The following parameter values are incompatible with their definitions: date_range_param"}

However I'm using the parameters stated in the redash api user guide which specifically gave an example for this query:

  "parameters": {
    "number_param": 100,
    "date_param": "2020-01-01",
    "date_range_param": {
      "start": "2020-01-01",
      "end": "2020-12-31"
    }
  },
  "max_age": 1800
}

Wondering if anyone can help me understand what the issue is? Thanks for any help! Current version of the code

function myFunction() {
   var api_key = "t8CCwHMvO2ksbooviLqMC4Yzr1TmRoCZcWJpoSKE"; // Please set your API key.
  var redashapi = "https://dashboard.campaignlab.ai/api/queries/2648/results";
  var sheetname = "Sheet1";
var payload = {
    parameters: {
      date_range_param: {
        start: "2025-03-01",
        end: "2025-03-02"
      }
    }
  };

  var response = UrlFetchApp.fetch(redashapi, {
    muteHttpExceptions: true,
     method: "POST",
    payload: Utilities.newBlob(JSON.stringify(payload)),
     headers: {authorization: "Key " + api_key }
  });
        Logger.log(response.getContentText());
//Storing Redash Cached Query result in this variable.
}

Solution

  • This is just my guess. How about the following modification?

    Modified script 1:

    function myFunction() {
      var redashapi = "https://dashboard.name/api/queries/0001/results?api_key=api_key";
      // var sheetname = "Sheet1"; // This is not used.
      var payload = {
        parameters: {
          date_range_param: {
            start: "2025-04-01",
            end: "2025-04-02"
          }
        }
      };
      var response = UrlFetchApp.fetch(redashapi, {
        muteHttpExceptions: true,
        method: "POST",
        payload: Utilities.newBlob(JSON.stringify(payload))
      });
      Logger.log(response.getContentText());
    }
    

    Modified script 2:

    function myFunction() {
      var api_key = "###"; // Please set your API key.
      var redashapi = "https://dashboard.name/api/queries/0001/results";
      // var sheetname = "Sheet1"; // This is not used.
      var payload = {
        parameters: {
          date_range_param: {
            start: "2025-04-01",
            end: "2025-04-02"
          }
        }
      };
      var response = UrlFetchApp.fetch(redashapi, {
        muteHttpExceptions: true,
        method: "POST",
        payload: Utilities.newBlob(JSON.stringify(payload)),
        headers: { authorization: "Key " + api_key } //  or { authorization: "Bearer " + api_key }
      });
      Logger.log(response.getContentText());
    }
    

    Note: