Yogesh Khater
Yogesh Khater

Reputation: 1958

New calendar event, created using Google service account isn't sending invitaion email to the attendees

I am creating a new event in Google Calendar by using Google's service account, and I have also set sendNotifications to true, but after creating an event, invitation emails are not sending to the attendees ??

  # new event to be created
  event = {
    'summary'=> summary,
    'description'=> description,
    'start'=> {'dateTime' => datetime },
    'end' => {'dateTime' => datetime },
    'sendNotifications' => true,
    'sequence' => sequence,
    'reminders' => {
      'useDefault' => false,
      'overrides' => [
        {'minutes' => 60, 'method' => 'email'}
      ]
    },  
    'attendees'=> [
      {
        'email'=> email
      }
    ]
  }

  # build client
  client = Google::APIClient.new application_name: "Test", application_version: "0.0.1"
  key = Google::APIClient::KeyUtils.load_from_pkcs12(key_file, key_secret)     

  client.authorization = Signet::OAuth2::Client.new(
    :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
    :audience => 'https://accounts.google.com/o/oauth2/token',
    :scope => 'https://www.googleapis.com/auth/calendar',
    :issuer => ENV['SERVICE_ACCOUNT_EMAIL'],
    :grant_type => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    :access_type => 'offline',
    :signing_key => key
  )

  # fetch access token
  client.authorization.fetch_access_token!

  # create new event
  service = client.discovered_api('calendar', 'v3')
  client.execute(:api_method => service.acl.insert,
                 :parameters => {'calendarId' => 'primary'},
                 :body => JSON.dump(event),
                 :headers => {'Content-Type' => 'application/json'})

Upvotes: 3

Views: 1320

Answers (1)

luc
luc

Reputation: 3782

sendNotifications is a property of the request, not of an event. See the documentation of an insert here: https://developers.google.com/google-apps/calendar/v3/reference/events/insert You can also try the explorer to see how exactly requests should look like: https://developers.google.com/apis-explorer/#p/calendar/v3/ (don't forget to authenticate in the top right corner).

Upvotes: 2

Related Questions