googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.44k stars 1.92k forks source link

Getting 'unknown sender' notification when creating google calender event via service account #3576

Open mster429 opened 1 month ago

mster429 commented 1 month ago
const auth = new GoogleAuth({
      scopes: [
        'https://www.googleapis.com/auth/calendar',
        'https://www.googleapis.com/auth/calendar.events'
      ],
      keyFile: './src/serviceaccount.json',
      clientOptions: {
        subject: 'xxxx@mydomain.com'
      }
    });

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

    const apiResponse = await calendar.events.insert({
      calendarId: "xxxx@mydomain.com",
      conferenceDataVersion: 1,
      requestBody: {
        start: {
          dateTime: "2024-10-10T08:00:00+09:00",
        },
        end: {
          dateTime: "2024-10-10T08:30:00+09:00",
        },
        attendees: [{ email: "me@gmail.com" }, { email: "xxxx@mydomain.com" }],
        summary: 'Test Event',
        description: 'Test Event created',
        guestsCanInviteOthers: true,
        conferenceData: {
          createRequest: {
            requestId: randomUUID(),
            conferenceSolutionKey: {
              type: 'hangoutsMeet'
            }
          }
        },
        reminders: {
          useDefault: false,
          overrides: [],
        },
        guestsCanModify: true,
        visibility: 'default',
      }
    });

I am using the above code to create a calender event using google calender api via google service account. sendUpdates parameter is false so that I don't get any notification via google about the event creation. But when I try this only the first time I am getting the below notification from google and i need to suppress/ disable it and i need help to get this resolved. unknown_sender Thanks in advance

Nondukishor commented 1 month ago

Can you try this one:

const { google } = require('googleapis');
const { GoogleAuth } = require('google-auth-library');
const { randomUUID } = require('crypto');

const auth = new GoogleAuth({
  scopes: [
    'https://www.googleapis.com/auth/calendar',
    'https://www.googleapis.com/auth/calendar.events'
  ],
  keyFile: './src/serviceaccount.json',
  clientOptions: {
    subject: 'xxxx@mydomain.com' // User under which the service account will operate
  }
});

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

const apiResponse = await calendar.events.insert({
  calendarId: "xxxx@mydomain.com",
  conferenceDataVersion: 1,
  requestBody: {
    start: {
      dateTime: "2024-10-10T08:00:00+09:00",
    },
    end: {
      dateTime: "2024-10-10T08:30:00+09:00",
    },
    attendees: [{ email: "me@gmail.com" }, { email: "xxxx@mydomain.com" }],
    summary: 'Test Event',
    description: 'Test Event created',
    guestsCanInviteOthers: true,
    conferenceData: {
      createRequest: {
        requestId: randomUUID(),
        conferenceSolutionKey: {
          type: 'hangoutsMeet'
        }
      }
    },
    reminders: {
      useDefault: false,
      overrides: [],
    },
    guestsCanModify: true,
    visibility: 'default',
  },
  sendUpdates: 'none' // Add this line to suppress notifications
});
mster429 commented 3 weeks ago

Hi @Nondukishor This is what was on the official documentation image Because we are heavily using the sync webhooks we are not going to use this option