Search code examples
phpgoogle-apigoogle-calendar-apigoogle-api-php-client

Sending Google Calendar API Confirmation email


I'm trying to make it so that once an event is created with Google Calendar API and an attendee is added, they will get a confirmation email.

Is this possible with the current Google Calendar API? (I'm using PHP for the back end ). I've tried with sendUpdates set to all and attendees[].responseStatus to needsAction but without any success.

$event = new Google_Service_Calendar_Event(array(
  'summary' =>'something',
  'location' => 'something',
  'description' => $name.' test',
  'start' => array(
    // 'dateTime' => '2015-05-28T09:00:00-07:00',
    'dateTime' => $start.':00-04:00',
    'timeZone' => 'America/Toronto',
  ),
  'end' => array(
    'dateTime' => $end.':00-04:00',
    'timeZone' => 'America/Toronto',
  ),
  'attendees' => array(
    array('email' => $email),
    'responseStatus' => 'needsAction',
  ),
  'reminders' => array(
    'useDefault' => FALSE,
    'overrides' => array(
      array('method' => 'email', 'minutes' => 24 * 60),
      array('method' => 'popup', 'minutes' => 10),
    ),
  ),
  'sendUpdates' => 'all',
  'visibility' => 'public',
));

$calendarId = 'vladc99@gmail.com';
$event = $service->events->insert($calendarId, $event);
echo "<a href='".$event->htmlLink."' taget='_blank'> Click here </a>";
echo "<a href='../'>Home</a>"; 

Thank you in Advance


Solution

  • sendUpdates is a request parameter, not an option of the request body

    In other words it is not located inside the request body.

    Modify your code as following:

    $event = new Google_Service_Calendar_Event(array(
      'summary' =>'something',
      'location' => 'something',
      'description' => $name.' test',
      'start' => array(
        // 'dateTime' => '2015-05-28T09:00:00-07:00',
        'dateTime' => $start.':00-04:00',
        'timeZone' => 'America/Toronto',
      ),
      'end' => array(
        'dateTime' => $end.':00-04:00',
        'timeZone' => 'America/Toronto',
      ),
      'attendees' => array(
        array('email' => $email),
        'responseStatus' => 'needsAction',
      ),
      'reminders' => array(
        'useDefault' => FALSE,
        'overrides' => array(
          array('method' => 'email', 'minutes' => 24 * 60),
          array('method' => 'popup', 'minutes' => 10),
        ),
      ),
      'visibility' => 'public',
    ));
    
    $calendarId = 'vladc99@gmail.com';
    $event = $service->events->insert($calendarId, $event, array('sendUpdates' => 'all'));
    echo "<a href='".$event->htmlLink."' taget='_blank'> Click here </a>";
    echo "<a href='../'>Home</a>";