Google Apps Script: retrieving Working Location from calendar
Asked Answered
O

3

5

a recent feature in Google Calendar allows users to select a working location (home, office, other) for every working day. Do you know if there is a way to retrieve this info using Apps Script ?

Thanks

Mathieu

Outright answered 7/9, 2021 at 10:23 Comment(5)
have you looked in the documentation?Elderberry
yes but nothing pops out. I also tried starting from a quick start projets and browsing through Events or Settings from the Calendar object but still nothing.Outright
I might guess that this would be part of meta dataReplica
Same question here - looked at the reference and tried the API explorer but I don't see this being returned?Stochastic
Hello @MathieuLenoir, if you check Iamblichus's answer, there is a link to a feature request to implement this.Clothespress
E
5

Answer:

This is currently not available to the API.

Reference:

Here is a list of all the settings available to the API: Settings.

You can notice that many settings from https://calendar.google.com/calendar/u/0/r/settings are not available, including Enable working location. Since this is a very recent feature, it's not strange that it hasn't yet been added to the API.

There is a Feature Request:

Another user suggested this feature to be implemented in the Calendar API. You can click on the star next to the issue number to give more priority to the request and to receive updates: https://issuetracker.google.com/199918380

Erland answered 9/9, 2021 at 12:47 Comment(0)
T
2

There is actually now an API for doing this available in Developer Preview: https://developers.google.com/calendar/api/guides/working-hours-and-location

Tenpenny answered 19/6, 2023 at 11:52 Comment(0)
H
1

You can now do so with Google Apps Script:

  • enroll to the Developer Preview Program here. When enrolling, you'll have to specify a GCP project number (not the Project ID). You might want to create a separate project for it in GCP
  • if you create a new GCP project, make sure to configure the OAuth Consent Screen (here) and add the Google Calendar API to the project (here)
  • create a new Google Apps Script Project. Go to Project Settings, and specify the Google Cloud Platform Project ID

Then, in the Google Apps Script, you can read the events with Calendar.Events.list, make sure to pass eventTypes: ['workingLocation'] as optionalArgs:

const calendarId = 'primary'

// Query parameters for the list request.
const optionalArgs = {
    eventTypes: ['workingLocation'],
    showDeleted: false,
    singleEvents: true,
    timeMax: '2023-07-10T00:00:00+01:00',
    timeMin: '2023-06-27T00:00:00+01:00',
  }

var response = Calendar.Events.list(calendarId, optionalArgs );

For more details, including a more fleshed out example (also for setting your work location), see the official documentation: https://developers.google.com/calendar/api/guides/working-hours-and-location

Hawger answered 7/7, 2023 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.