Alan Mroczek
Alan Mroczek

Reputation: 1209

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');
  webmasters.searchanalytics.query({
    auth: auth,
    siteUrl: 'http%3A%2F%2Falanmroczek.pl%2F',
    startDate: "2016-09-20",
    endDate: "2016-10-14"
  }, function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }

    console.log(response);
  });
}

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: 'www.googleapis.com',
 port: null,
 hostname: 'www.googleapis.com',
 hash: null,
 search: '?startDate=2016-09-20&endDate=2016-10-14',
 query: 'startDate=2016-09-20&endDate=2016-10-14',
 pathname: '/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query',
 path: '/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query?startDate=2016-09-20&endDate=2016-10-14',
 href: 'https://www.googleapis.com/webmasters/v3/sites/http%3A%2F%2Falanmroczek.pl%2F/searchAnalytics/query?startDate=2016-09-20&endDate=2016-10-14' },

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.

Upvotes: 0

Views: 578

Answers (3)

Alan Mroczek
Alan Mroczek

Reputation: 1209

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.

Upvotes: 1

Micheal P.
Micheal P.

Reputation: 55

i work on the similar code. This Reference helped me.

Just have a look: NodeJS & Goodgle Express API

Upvotes: 0

David R
David R

Reputation: 15667

Backend Errors which are being returned from Google API calls will have 503 as its error code which means "Service Unavailable".

Check the various API's and its status here and ensure the service that you are trying to hit is up and running fine.

https://www.google.com/appsstatus#hl=en&v=status

Hope this helps!

Upvotes: 0

Related Questions