Date range parameters failing when sending data from Redash API to Google Sheets

I’m working on a Google Apps Script to pull data from Redash and populate a Google Sheet. After switching from using body to payload in my request, I keep getting this error message:

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

I followed the official Redash API documentation which shows this exact format for date parameters:

{
  "parameters": {
    "count_param": 50,
    "start_date": "2020-02-15",
    "period_range": {
      "begin": "2020-02-15",
      "finish": "2020-11-30"
    }
  },
  "max_age": 3600
}

Here’s my current script that’s causing the issue:

function executeQuery() {
   var apiKey = "abc123def456ghi789jkl012mno345pqr678stu"; 
  var queryEndpoint = "https://mycompany.redash.io/api/queries/1234/results";
  var targetSheet = "Data";
  
var requestData = {
    parameters: {
      period_range: {
        begin: "2025-01-15",
        finish: "2025-01-16"
      }
    }
  };

  var apiResponse = UrlFetchApp.fetch(queryEndpoint, {
    muteHttpExceptions: true,
    method: "POST",
    payload: Utilities.newBlob(JSON.stringify(requestData)),
    headers: {authorization: "Key " + apiKey }
  });
  
  Logger.log(apiResponse.getContentText());
}

Can anyone help me figure out what’s wrong with my date range formatting? Thanks!

The parameter name mismatch is your problem. Your Redash query expects date_range_param but you’re sending period_range. I hit this same issue last month - the parameter names in your payload have to exactly match what’s in the Redash query editor. Check query #1234 in Redash and look at the parameter settings for the actual name. Some Redash setups are also picky about date formats. I had to switch from YYYY-MM-DD to MM/DD/YYYY for one of our instances. If fixing the name doesn’t work, try changing the date format. Also, ditch the Utilities.newBlob() wrapper. Redash API wants plain JSON, not a blob object. Just use payload: JSON.stringify(requestData) directly.

Had this exact problem when connecting Redash to our dashboard. Yeah, it’s the parameter name mismatch like others said, but here’s what actually works: run your query manually in Redash first, then check the network tab in dev tools. You’ll see the exact payload that works. Found out some of our queries had different parameter names than what showed in the UI - old configs were the culprit. Once you fix the parameter names, add some error handling since Redash gets cranky with auth and rate limits. Pro tip: use the max_age parameter if you’re running this a lot - helps with caching.

hey, your parameter names don’t match - the error says date_range_param but you’re sending period_range. also, skip the newBlob and just use the JSON string directly. try payload: JSON.stringify(requestData) instead - that fixed the same issue for me with Redash API calls.

The Problem:

You’re receiving a "The following parameter values are incompatible with their definitions: date_range_param" error when trying to fetch data from the Redash API using a Google Apps Script. Your script uses the period_range parameter, while the Redash query expects date_range_param.

:thinking: Understanding the “Why” (The Root Cause):

The error arises from a mismatch between the parameter name used in your Google Apps Script and the parameter name expected by your Redash query. The Redash API is case-sensitive and requires an exact match for parameter names. Your script is sending data with a period_range key, but your Redash query likely uses date_range_param. This inconsistency causes the API to reject the request.

:gear: Step-by-Step Guide:

  1. Identify the Correct Parameter Name: Go to your Redash query (query ID 1234 in your example). In the query editor, carefully examine the parameters section. Find the exact name of the parameter used for the date range. It’s highly likely it’s named date_range_param, but double-checking is essential.

  2. Correct the Parameter Name in Your Script: Update your Google Apps Script to use the correct parameter name. Replace period_range with the name you found in Step 1. Your requestData should look like this (assuming date_range_param is the correct name):

var requestData = {
  parameters: {
    date_range_param: {
      begin: "2025-01-15",
      finish: "2025-01-16"
    }
  }
};
  1. Remove Utilities.newBlob(): The Redash API expects a JSON payload, not a Blob object. Remove the Utilities.newBlob() wrapper and directly use JSON.stringify(requestData):
var apiResponse = UrlFetchApp.fetch(queryEndpoint, {
  muteHttpExceptions: true,
  method: "POST",
  payload: JSON.stringify(requestData), // Removed Utilities.newBlob()
  headers: {
    authorization: "Key " + apiKey,
    "Content-Type": "application/json" // Add Content-Type header
  }
});
  1. Add the Content-Type Header: Include the "Content-Type": "application/json" header in your request to explicitly inform Redash that you’re sending JSON data.

  2. Test and Verify: Run your script again. The error should be resolved if the parameter name was the only issue.

:mag: Common Pitfalls & What to Check Next:

  • Date Format: Even with the correct parameter name, Redash might be sensitive to date formats. If the issue persists, try different formats (e.g., “YYYY-MM-DD”, “MM/DD/YYYY”).
  • API Key: Double-check that your apiKey is correct and has the necessary permissions.
  • Redash Query: Ensure the Redash query itself is functioning correctly. Try running it directly in the Redash interface to rule out any problems on the Redash side.
  • Network Issues: Verify that your Google Apps Script has network access and can communicate with the Redash API. Check your network connectivity.
  • Rate Limits: Redash might have rate limits. If you’re making many requests, consider implementing error handling and retry logic, or use the max_age parameter to leverage caching.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.