2
votes

I am experimenting with node.js and Google's bigQuery and can successfully make requests to get a list of public datasets and details of an individual dataset, but when I try to query one I get 400 'Required parameter is missing', but it does not tell me which parameter. My code is below:

var options = {
  host: 'www.googleapis.com',
  headers: {'Authorization': 'Bearer ' + accessCode},
  path: '/bigquery/v2/projects/bigquery-public-data/queries',
  method: 'POST'
};

var query = {
  kind: 'bigquery#queryRequest',
  query: "SELECT * FROM [hacker_news.full_201510]",
  maxResults: 10,
  defaultDataset: {
    datasetId: 'hacker_news',
    projectId: 'bigquery-public-data'
  },
  timeoutMs: 10000,
  dryRun: true,
  useQueryCache: true,
  useLegacySql: true
};

var callback = function(response) {
  var str = '';

  response.on('data', function (chunk) {
    str += chunk;
  });

  response.on('end', function () {
    console.log(str);
  });
}

var req = http.request(options, callback);
req.write(JSON.stringify(query));
req.end();

Any suggestions?

1
Did you ever resolve this? I'm having the same problem. - atp
I'm getting the same problem now too :( - gunit

1 Answers

0
votes

You seem to include all required parameters from this documentation: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query

My suggestion is to use the Node.js client library, so that you do not have to hand-craft these requests.

In this document, you can scroll down and under examples select node.js.