google-api-nodejs-client
google-api-nodejs-client copied to clipboard
startDate field is required.
Im having an issue with the google webmasters API v19. I able to get authenticated and grab a list of websites, but as soon as I try to run a general query I get some maddening errors that don't immediately make any sense.
My code:
// Get todays date for the query
const today = moment().format('Y-MM-DD');
// Build the query
const params = {
siteUrl: encodeURIComponent(website),
requestBody: {
startDate: "1994-06-30",
endDate: today,
dimensions: [
"query",
"page"
],
}
};
// Execute
webmasters.searchanalytics.query(params, (err, resp) => {
if(err) {
console.log(err);
return reply();
}
console.log(resp);
reply(resp);
});
I print out my params variable to double check the contents when a response is given. However, I keep getting the following error, even though my params are correctly defined:
My params echoed above the error message:
{ params:
{ siteUrl: 'http%3A%2F%2Fchrisrempel.com%2F',
requestBody:
{ startDate: '1994-06-30',
endDate: '2018-05-09',
dimensions: [Array] } } }
Error message:
{ Error: startDate field is required.
endDate field is required.
at Request._callback (/Applications/MAMP/htdocs/zag-api/zag-api/node_modules/google-auth-library/lib/transporters.js:85:15)
at Request.self.callback (/Applications/MAMP/htdocs/zag-api/zag-api/node_modules/request/request.js:186:22)
at emitTwo (events.js:125:13)
at Request.emit (events.js:213:7)
at Request.<anonymous> (/Applications/MAMP/htdocs/zag-api/zag-api/node_modules/request/request.js:1163:10)
at emitOne (events.js:115:13)
at Request.emit (events.js:210:7)
at IncomingMessage.<anonymous> (/Applications/MAMP/htdocs/zag-api/zag-api/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
code: 400,
errors:
[ { domain: 'global',
reason: 'required',
message: 'startDate field is required.',
locationType: 'parameter',
location: 'start_date' },
{ domain: 'global',
reason: 'required',
message: 'endDate field is required.',
locationType: 'parameter',
location: 'end_date' } ] }