How do I create an Out of office type Calendar Event via the REST API?
Asked Answered
D

5

21

Google Calendar has a new event type called "Out of office" that automatically will decline any events it is placed over and others that come in during the scheduled time of the event.

I inspected one of these event objects via the API and briefly checked the Google Calendar API documentation to see if there was a way to create these programmatically. I work on a system that schedules events on people's calendars when they are going to be out of the office as all day events to provide visibility to the rest of the staff. I would like to change these to be true Out of office event types if its possible via the API.

Deciduous answered 31/7, 2018 at 16:15 Comment(3)
I think this is a pretty new feature that Gmail had launched that goes with their new calendar UI, it may be only applicable for the web and not yet added to the API. You may want to create a feature request for other developers that are looking forward for this feature in the API.Ninebark
Thanks. I went to log an issue but it looks like somebody already did yesterday.Deciduous
These are the issues if someone wants to star or track: issuetracker.google.com/issues/112063903 issuetracker.google.com/issues/122674818Bovine
E
13

The short answer: It does not work currently (as of 12/2023)

According to the Google Calendar API the eventType property is now writable, but onlye default and workingLocation events can be created through the API.

eventType [string]: Specific type of the event. This cannot be modified after the event is created.

Possible values are:

  • "default" - A regular event or not further specified.
  • "outOfOffice" - An out-of-office event. An outOfOfficeProperties parameter must be supplied to make a valid event (even if empty).
  • "focusTime" - A focus-time event. A focusTimeProperties parameter must be supplied to make a valid event (even if empty).
  • "workingLocation" - A working location event.

Currently, only "default " and "workingLocation" events can be created using the API. Extended support for other event types will be made available in later releases.


The short answer: It does not work currently (as of 08/2022)

The Google Calendar API currently exposes the eventType property as read-only. It will be discarded when sent in an insert payload.

eventType [string]: Specific type of the event. Read-only.

Possible values are:

  • "default" - A regular event or not further specified.
  • "outOfOffice" - An out-of-office event.

As mentioned by @ercliou in the comments, the ticket can be tracked here: issuetracker.google.com/issues/112063903

Evania answered 19/5, 2021 at 11:59 Comment(1)
This does work now: ``` { "start": { "dateTime": "2023-12-09T08:00:00Z" }, "end": { "dateTime": "2023-12-09T20:00:00Z" }, "summary": "Test OOO", "eventType": "outOfOffice", "outOfOfficeProperties": { "autoDeclineMode": "declineAllConflictingInvitations", "declineMessage": "Out of Office" } } ```Urga
L
1

It will be coming in upcoming release as mentioned in their docs - https://developers.google.com/calendar/api/v3/reference/events/insert

Please check the attached image

Larcener answered 8/11, 2023 at 3:54 Comment(0)
B
1

It has been implemented recently: https://developers.google.com/calendar/api/guides/calendar-status?hl=en

Here's a working example of it working in java:

In pom.xml:

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-calendar</artifactId>
        <version>v3-rev20231123-2.0.0</version>
    </dependency>

Java code:

            EventOutOfOfficeProperties outOfOfficeProperties = new EventOutOfOfficeProperties();
            outOfOfficeProperties.setAutoDeclineMode("declineOnlyNewConflictingInvitations");
            outOfOfficeProperties.setDeclineMessage("Decline message");


            Event event = new Event()
                    .setId("1234")
                    .setEventType("outOfOffice")
                    .setTransparency("opaque")
                    .setSummary("Summary")
                    .setOutOfOfficeProperties(outOfOfficeProperties);


            DateTime startDateTime = new DateTime("2023-12-04T09:00:00-03:00");


            EventDateTime start = new EventDateTime()
                    .setTimeZone("America/Argentina/Buenos_Aires")
                    .setDateTime(startDateTime);
            event.setStart(start);

            DateTime endDateTime = new DateTime("2023-12-04T18:00:00-03:00");
            EventDateTime end = new EventDateTime()
                    .setTimeZone("America/Argentina/Buenos_Aires")
                    .setDateTime(endDateTime);
            event.setEnd(end);

            service.events().insert("yourCalendarId",event ).execute();

If you get 400 bad request responses with no further description, check both the DateTime format and the id provided for the event.

Blither answered 3/12, 2023 at 13:2 Comment(0)
U
1

Out of Office is now supported. If you create an event with type outOfOffice make sure you set outOfOfficeProperties:

{
  "start": {
    "dateTime": "2023-12-09T08:00:00Z"
  },
  "end": {
    "dateTime": "2023-12-09T20:00:00Z"
  },
  "summary": "Test OOO",
  "eventType": "outOfOffice",
  "outOfOfficeProperties": {
    "autoDeclineMode": "declineAllConflictingInvitations",
    "declineMessage": "Out of Office"
  }
}

https://developers.google.com/calendar/api/v3/reference/events/insert

"outOfOffice" - An out-of-office event. An outOfOfficeProperties parameter must be supplied to make a valid event (even if empty).

Some properties are denied like description, so make sure to only add necessary fields.

Here is an example in the Google API Explorer.

Urga answered 4/12, 2023 at 9:53 Comment(2)
This not working for me, getting this error Google::Apis::ClientError: invalid: Attempt made to modify an event in a way which is not valid for this event type.Ideo
@AndrewCetinic It happened to me when I tried to pass date instead of dateTime. Seems like it supports only timed events.Necrophilia
G
-3

The only thing that seemingly marks an event as out of office is a private extended property on the event resource:

"extendedProperties": {
    "private": {
        "everyoneDeclinedDismissed": "-1"
    }
}

Looking at https://developers.google.com/calendar/v3/reference/events/insert the attribute extendedProperties.private is writeable so you should be able to set it there.

Glaciate answered 21/11, 2018 at 20:15 Comment(1)
This didn't work for me. I tried it via Google's API explorer with a payload like this. I also tried setting everyoneDeclinedDismissed to "0" and "1" and those didn't work either. The event was not an "out of office" event and it didn't decline other meetings.Treillage

© 2022 - 2024 — McMap. All rights reserved.