google-api-nodejs-client: JWT Error

Hello,

I am currently getting the error:

{ [Error: Not Found] code: 404 errors: [ { domain: ‘global’, reason: ‘notFound’, message: ‘Not Found’ } ] }

When trying to use the calendar api using JWT. I am struggling to find this error message and how to debug this online. Please help! My code is the following:

jwtClient.authorize(function(err, tokens) {
  if (err) {
    console.log(err);
    return;
  }

  // Make an authorized request to list Drive files.
  calendar.events.list({ 
    auth: jwtClient,
    calendarId: calendarId,
    timeMin: (new Date()).toISOString(),
    maxResults: 100,
    singleEvents: true,
    orderBy: 'startTime' 
  }, function(err, resp) {
    // handle err and response
    console.log("===============")
    console.log(err)
    console.log(resp)
  });
});

The call works when i authorize via auth.OAuth2…

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I am trying to fetch all emails under our domain. I have all admin rights anda I created service account with Domain wide delegation. This is my code:

const google = require('googleapis');
const gmail = google.gmail('v1');
const directory = google.admin('directory_v1');
const scopes = [
  'https://www.googleapis.com/auth/gmail.readonly',
  'https://www.googleapis.com/auth/admin.directory.user.readonly'
];
const key = require('./service_key.json');

var authClient = new google.auth.JWT(
  key.client_email,
  null,
  key.private_key,
  scopes,
  null
);

authClient.authorize(function(err, tokens){
  if (err) {
    console.log(err);
    return;
  }

  directory.users.list(
    {
      auth: authClient,
      customer: 'my_customer',
      maxResults: 250,
      orderBy: 'email'
    }, (err, resp) => {
    if (err) {
      console.log(err);
      return;
    }

    console.log(resp);
  })

})

and I still get error

{ Error: Domain not found.
    at Request._callback (/home/kunok/code/sampleApi/node_modules/google-auth-library/lib/transporters.js:85:15)
    at Request.self.callback (/home/kunok/code/sampleApi/node_modules/google-auth-library/node_modules/request/request.js:198:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/home/kunok/code/sampleApi/node_modules/google-auth-library/node_modules/request/request.js:1057:14)
    at emitOne (events.js:101:20)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/home/kunok/code/sampleApi/node_modules/google-auth-library/node_modules/request/request.js:1003:12)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
  code: 404,
  errors: 
   [ { domain: 'global',
       reason: 'notFound',
       message: 'Domain not found.' } ] }