Alan Mroczek Alan Mroczek - 1 year ago 57
Node.js Question

NodeJS & googleapis, POST request not working?

I've got a problem with google api in NodeJS with hapi. I downloaded files with npm install googleapis and google-auth-library. Everything is setup correctly.

function listData(auth) {
let webmasters = google.webmasters('v3');
auth: auth,
siteUrl: '',
startDate: "2016-09-20",
endDate: "2016-10-14"
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);


I'm authorised to that scope by this app (if not it throws an error, so I'm sure that this part is okey). When I done listing my gmail folders it works perfectly. Wrong may be only this part of code or googleapis. Strange for me is that:

When I console.log request to Google API:

protocol: 'https:',
slashes: true,
auth: null,
host: '',
port: null,
hostname: '',
hash: null,
search: '?startDate=2016-09-20&endDate=2016-10-14',
query: 'startDate=2016-09-20&endDate=2016-10-14',
pathname: '/webmasters/v3/sites/',
path: '/webmasters/v3/sites/',
href: '' },

Query, path and href looks like normal GET, I have no idea why. I tried to override it but still I get "backend error".

EDIT: Gmail list folders via GET, thats why I pointed out POST.

Answer Source

It's probably issue with googleapis for node.js. It's sending data via GET not required POST and JSON. We have to do it manually.