0

I use node.js to query data from search console api. I get response status 500 and message "backend error".

I have tried some solutions but they did not work:

  • check API key(set key restriction to "none" because I do not have ipv6 address)
  • send json data instead of js object

Below is my code snippet.

  var data = {
    startDate: '2016-12-01',
    endDate: '2016-12-20',
    dimensions: ['query'],
    rowLimit: '1000'
  };

  var options = {
    url: 'https://content.googleapis.com/webmasters/v3/sites/' + siteUrl +'/searchAnalytics/query?key=' + apiKey + '&access_token=' + accessToken,
    headers: {
      'content-type': 'application/json',
    },
    json: true,
    method: 'post',
    body: JSON.stringify(data)
  };

  function callback(error, response, body) {
    if(!error && response.statusCode == 200) {
      console.log(response);
    } else {
      console.log(body.error.code + ': ' + response.statusMessage + ' (' + body.error.message + ')');
    }
  }

  request(options, callback);

Any ideas?

Cythilya
  • 99
  • 1
  • 9
  • First that is the wrong endpoint second that method requires authentication so key won't work. You might want to consult the documentation – Linda Lawton - DaImTo Dec 26 '16 at 21:26
  • @DaImTo I just show the server side snippet, not all of them. I get the access token from client side, and use ajax to send back to the server side. In the above snippet, I put this access token in the variable "access_token". "api_key" is get from API console setting. – Cythilya Dec 27 '16 at 07:02

0 Answers0