5

could you please give me a hint on how to share a single event via google calendar api?

That is I'd like to invite other users to see the event programmatically without sharing the whole calendar. To mimic the "Add guests" UI action The google calendar Add guests

Kara
  • 6,115
  • 16
  • 50
  • 57
Igor
  • 2,619
  • 6
  • 24
  • 36

3 Answers3

9

As Claudio mentioned, you need to use the Google Calendar Advanced API for this.

You'll want to use a patch because you don't want to replace all the other data on the calendar invite. However, even in the case of patch, since the attendees lives in an array, if you attempt to pass a patch such as this:

{
  attendees: [ { email: "new@example.com"} ]
}

... it'll replace all old invitees (i.e. it'll remove anyone that was on the invite before you called patch). To fix this, you must first get the current invitees, add a new person to the array, and then send a patch.

You can see a detailed example of this in this answer which also explains how to use Google Apps Scripting to ensure an email is sent to the user when adding them to a calendar event (see the addGuestAndSendEmail() method in that post).

Senseful
  • 86,719
  • 67
  • 308
  • 465
5

You can use the API to add people to the attendees collection:

https://developers.google.com/google-apps/calendar/v3/reference/events/update

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • 5
    Seems like this will replace the array, removing old guests if they are not part of the new array. Is there a way to add guests (and not remove any) without having to fetch the value of the old array? – Senseful Apr 04 '19 at 07:02
1

refer the following request.

method: POST

endpoint: https://www.googleapis.com/calendar/v3/calendars/primary/events?sendUpdates=all

here, sendUpdates means when you add any guest so he would get an invitation mail used based on scenario.

Input Json: { "kind": "calendar#event", "etag": "etag", "status": "confirmed", "summary": "JayKara", "description": "eqwbdjhwhhwhhwrhjehrhejhfj", "location": "America", "creator": { "email": "@mail.com", "self": true }, "organizer": { "email": "@mail.com", "self": true }, "start": { "date": "2019-12-23" }, "end": { "date": "2019-12-24" }, "originalStartTime": { "date": "2019-12-24" }, "visibility": "public", "attendees": [ { "email": "****@mail.com" //this guys are the guest } ] }.

After that there is no patch method required your guest guys will receive an invitation whenever update event

Cheers!