0

I have read the google calendar API docs but I couldn't find a way of inviting guest outside the account's organization, is this possible?

This is my code with the NodeJS client:

const auth = new google.auth.GoogleAuth({
  keyFile: 'src/google-api/calendar-auth.json',
  scopes: ['https://www.googleapis.com/auth/calendar'],
});

const calendar = google.calendar({ version: 'v3', auth });

calendar.events.insert({
    calendarId: 'email-of-organization',
    sendUpdates: 'all',
    requestBody: {
        start: {
          dateTime: startDate.toISOString(),
          timeZone: 'utc',
        },
        end: {
          dateTime: endDate.toISOString(),
          timeZone: 'utc',
        },
        summary: 'a summary',
        description: 'a description',
        attendees: [{ email: 'email@outside.org' }], // this email is outside my organization
    },
});

The error: Service accounts cannot invite attendees without Domain-Wide Delegation of Authority

Even if I setup Domain-Wide Delegation, the error persists.

enter image description here

agustin37
  • 121
  • 6

1 Answers1

1

Basically you authorizing your service account to access data on behalf of users in your domain when you delegate domain-wide authority to your service account. See Delegating domain-wide authority to the service account

Once you finished delegating domain-wide authority, your application now has the authority to make API calls as users in your domain (to "impersonate" users). When you prepare to make authorized API calls, you specify the user to impersonate.

It is possible to invite guests outside your domain (using your user account or a service account). You have the option to warn the users when inviting guests outside your domain. See Allow external invitations in Google Calendar events

I tried creating an event using my user account and add a guest from outside the domain with events.insert. It was successfully created. Therefore, if you let your service account to impersonate a user in your domain it should be able to create events and invite guests outside your domain as well

Ron M
  • 5,791
  • 1
  • 4
  • 16
  • Should I use (impersonate) the service account calendar Id to send those emails? I cannot get rid of that error: Service accounts cannot invite attendees without Domain-Wide Delegation of Authority. I already enabled that, and it persists. – agustin37 Jan 08 '21 at 20:17
  • Yes, please try impersonating a user account. [Reference1](https://stackoverflow.com/questions/50335892/how-to-impersonate-an-admin-user-when-using-getclient-in-the-google-api-nodejs), [Reference2](https://github.com/googleapis/google-api-nodejs-client/issues/1699) – Ron M Jan 08 '21 at 21:08
  • Please follow the step2 provided [here](https://stackoverflow.com/questions/60760959/google-calendar-api-service-account-error) as well. – Ron M Jan 08 '21 at 21:17
  • Thanks for the help, couldn't make it work. I followed all the steps of the links you sent and documentation, and other resources I found, and I couldn't get past the `Service accounts cannot invite attendees without Domain-Wide Delegation of Authority` error. – agustin37 Jan 11 '21 at 19:14
  • Sorry to hear that, I really can't reproduce your issue due to lack of required environment. You may also want to try raising this concern to the [workspace support](https://support.google.com/a/answer/1047213?hl=en), they can help you with your API issue – Ron M Jan 11 '21 at 19:22
  • 2
    Ok after 3 days, I could create the event. It was a problem setting the subject, It seems that the `google.auth.GoogleAuth` auth doesn't have a clear way of putting the subject, at least I couldn't do it properly, so I changed to `google.auth.JWT` auth that accepts the subject in the constructor. Thanks! – agustin37 Jan 12 '21 at 13:23