1
votes

I am trying to use Google Calendar API to create event and invite multiple attendees.

foreach($email_invite_arr as $item){
    if($item){
        $attendee = new Google_Service_Calendar_EventAttendee();
        $attendee->setEmail($item);
        $attendee_arr[]= $attendee;
    }
}
$event->setAttendees($attendee_arr);

$optParams = Array(
    'sendNotifications' => true,
    'maxAttendees' => 10
);
$createdEvent = $service->events->insert('primary', $event, $optParams);

Everything works fine. The event is getting created with all attendees. But Email notifications are not getting sent. What am I doing wrong here?

3
Email notification are not sent for the events which are created in the past. Also, please check remindOnRespondedEventsOnly whether it is set to true or false(for the calendar which you are trying to insert event). If this is "true" then event reminders will be sent only for events with the user’s response status “Yes” or "may be". - SGC
Please also check techromance.com/2018/07/08/google-calendar-api-enigma-solved, I was wandering around the similar problem, have solved couple of hours back with some hack around. - Satys

3 Answers

2
votes

You don't need the patch function. The sendNotification works just fine with creating the event.

What I found was that the current guide didn't work for me to cycle through attendees. Here's what worked for me:

foreach ($staffUserArr as $staffEmail)
{
    $attendee1 = new Google_Service_Calendar_EventAttendee();
    $attendee1->setEmail($staffEmail);

    $attendees[] = $attendee1;
}

$newEvent->attendees = $attendees;

$optParams = Array(
        'sendNotifications' => true,
);

$service->events->insert('primary',$newEvent,$optParams);
0
votes

Notifications are set by the attendee's calendar. The event organizer can only set notifications for their own calendar not for attendees. Think about it in terms of sending a formal party invitation via snail mail, it's certainly not the host's job to remind people to leave the house 20 minutes before the party starts!

The attendee notifications will be set based on the attendee's default notifications for the calendar unless the attendee sets custom notifications.

If you really want to set the notifications for the attendee, you'll need to be authenticated as each attendee.

0
votes

So there seems to be a problem with insert method of Calendar API. I followed the resolution suggested here : https://code.google.com/p/google-apps-script-issues/issues/detail?id=574 and it worked. Following is my modified code :

foreach($email_invite_arr as $item){
    if($item){
        $attendee = new Google_Service_Calendar_EventAttendee();
        $attendee->setEmail($item);
        $attendee_arr[]= $attendee;
    }
}

$optParams = Array(
    'sendNotifications' => true,
);
$createdEvent = $service->events->insert('primary', $event);

$event->setAttendees($attendee_arr);
$service->events->patch('primary',$createdEvent->getId(),$event, $optParams );

The key here is the patch method.