soundswaste
soundswaste

Reputation: 3074

Google Calendar API - sendNotifications is not working

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?

Upvotes: 1

Views: 4077

Answers (3)

user8735467239
user8735467239

Reputation: 386

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);

Upvotes: 2

soundswaste
soundswaste

Reputation: 3074

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.

Upvotes: 0

Jay Lee
Jay Lee

Reputation: 13528

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.

Upvotes: 0

Related Questions