## Sending Via API <img src="https://developers.google.com/static/calendar/api/images/event-attendees.png"> ### Reference notes - [Quickstart](https://developers.google.com/calendar/api/quickstart/js) Guide from Google Developers - Google Objects: - `Event` - calendar event, like an appointment in our case - `Calendar` - a collection of events - `Calendar List` - list of all a users calendars - `Setting` - properties of a calendar - `ACL` - access control rule granting different levels of access to a calendar ### Setting up the API: - Enable the API in the [Google Cloud](https://console.cloud.google.com/projectselector2/apis/enableflow?apiid=calendar-json.googleapis.com&supportedpurview=project) - Create the project - Within your code, you would need to have some sort of google authentication, so that they can access this, and it would go to their primary calendar - ==If you wanted to add to their calendar lists, you would need access to their accounts== ### Building the API Call: 1. Making the event to input. ```javascript= const event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': 'lpage@example.com'}, {'email': 'sbrin@example.com'} ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10} ] } }; ``` 2. Do the request and return the link to the newly created event: ```javascript= const request = gapi.client.calendar.events.insert({ 'calendarId': 'primary', 'resource': event }); request.execute(function(event) { appendPre('Event created: ' + event.htmlLink); }); ``` ## Sending via email - can just send a link, don't need to even connect to the API: ``` https://calendar.google.com/calendar/r/eventedit?action=TEMPLATE&dates=20230325T224500Z%2F20230326T001500Z&stz=Europe/Brussels&etz=Europe/Brussels&details=EVENT_DESCRIPTION_HERE&location=EVENT_LOCATION_HERE&text=EVENT_TITLE_HERE ``` The properties are as follows: - Start and end dates and times: Use ISO 8601 format. In the above example, replace 20230325T224500Z and 20230326T001500Z. - Start and end time zones: Format as an IANA Time Zone Database name. Place the time zones in the stz and etz fields. - Event description: Must be URL encoded. - Event location: Must be URL encoded. - Event title: Must be URL encoded. Can also send with an ICS file: - Can use [`iCalender`](https://icalendar.org/RFC-Specifications/iCalendar-RFC-5545/) which should also auto add to their calendar if they accept / trust you - Looks better, more complicated ![](https://hackmd.io/_uploads/BkFxIuV93.png)