Johan
Johan

Reputation: 26

can I set/change the owner Google Calendar event using an Apps script?

I wrote the following function in Apps Script to create a Calendar Event (based on information in a Google Sheet), but would like one of the attendees to be the owner so they can see the waiting room for guests. Can I transfer ownership of the event or is there another way to make that happen?

function createEvent(title,start,end,teacher,student) {
  // https://developers.google.com/apps-script/advanced/calendar
  // https://developers.google.com/calendar/v3/reference/events
  var event = {
    summary: title,
    description: 'Teacher / student meeting',
    start: {
      dateTime: start.toISOString()
    },
    end: {
      dateTime: end.toISOString()
    },
    guestsCanInviteOthers: "no",
    conferenceData: {
      createRequest: {
        conferenceSolutionKey: {
          type: "hangoutsMeet"
        },
        requestId: start,
      },
    },
    attendees: [
    {email: teacher},
    {email: student}
    ],
  };
    event = Calendar.Events.insert(event, calendarId, {sendNotifications: false, conferenceDataVersion: 1} );
  return event.id;
}

Upvotes: 0

Views: 2245

Answers (2)

ziganotschka
ziganotschka

Reputation: 26796

There are two options to assign the event ownership to a different user

1. Transfer the ownership of an already existing event

  • This is unfortunately not possible by setting the creator or organizer property, since those parameters are only read-only.
  • To transfer the ownership, you need to use the method Events: move. Note that in this case the event will be moved out of the calendar it is currently located into the calendar of the person who is meant be asisgned as the new owner

2. Use a service account with domain-wide delegation

  • This allows you perform requests on behalf of any user of your domain
  • In other words, you can create events on another user's behalf by impersonating him.
  • In Apps Script you do so by using the OAuth2 library
  • See here for a sample

Upvotes: 2

Diego
Diego

Reputation: 9571

Set the guestsCanSeeOtherGuests property to true.

var event = {
  // ... 
  guestsCanInviteOthers: false, // expected a boolean, not the string "no"
  guestsCanSeeOtherGuests: true
};

If using CalendarApp, you can call .setGuestsCanSeeGuests(true) on the CalendarEvent.

Upvotes: 1

Related Questions