Error with Query.setQuery() in Google Visualization API: 'Missing query for request id: undefined'

Integrating the Google Visualization API with a spreadsheet fails when applying a select query. See the revised code snippet below:

google.load('visualization', '1.0', { packages: ['table'] });
google.setOnLoadCallback(executeQuery);

function executeQuery() {
  var sheetUrl = 'https://docs.google.com/spreadsheets/d/your_spreadsheet_id/edit#gid=0';
  var vizQuery = new google.visualization.Query(sheetUrl);
  vizQuery.setQuery('select Col1, Col2');
  vizQuery.send(processResult);
}

function processResult(response) {
  if (response.isError()) {
    console.error('Query error: ' + response.getMessage());
    return;
  }
  console.log(response.getDataTable());
}

Based on my experience, this error typically indicates that the query isn’t recognized because the URL doesn’t point to a valid data source. I encountered a similar issue when I was pulling data from a sheet; switching to the published CSV or using the ‘gviz/tq’ endpoint instead of the edit link resolved it for me. Also, verify that the spreadsheet settings allow public access or sharing for the API call to work correctly. Trying these adjustments might help alleviate the error in your code.

hey try using the export url from your sheet instead of the edit link. sometimes the edit url doesn’t support queries so swapping it out might fix it.