Remove Resource (e.g. conference room) from an Event using Google Calendar API - google-apps-script

I'm looking to write an app that will use Google Calendar API's to remove a resource (e.g. a conference room) from an event, if it's discovered that the room does not end up being needed. Obviously the call to the API will be with administrative permissions, but we won't have access to individual user accounts to remove the resource from the event / invite.
Does anyone know of any way to use Google Calendar API's to update / alter the resources that are assigned to a meeting?
Thanks!

Rooms are added to events as attendees and a copy is created on their calendar. You will just need to find the right event and delete it from the room's calendar (using Calendar API). Administrative permissions should give you all the access you need.

You can also remove a Room from an event as the Room if you have the Room's authentication credentials. You use the Rooms credentials and the https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventId} endpoint on the Room's primary calendar. This will not delete the event from the organizer's calendar.
Note: Regardless of the sendNotifications flag, Google will send a notification to the organizer when room delete/removes itself from an event (i.e. each time the endpoint is called). There is no workaround. If the organizer has all notifications turned off then they will not see these emails but it's still sent.

I think removing resources from an event can be done by using Google Apps Calendar Resource API. This API allows admin of the domain to add resources that users in the domain will be able to schedule on their calendars.
To delete a calendar resource, send a DELETE request to a resource ID's feed URL.
DELETE https://apps-apis.google.com/a/feeds/calendar/resource/2.0/{domain name}/{resourceId}

Related

How to make changes to a single user's google calendar using google apps script

I'm designing a google apps script that is linked to a bot that needs to add and delete events to a specific user's calendar. I need to find a way to do this without giving edit access to all people with access to the script. I was thinking of using the calendar api but that uses oauth2.0. Is there a way to use an api key instead? Another option I was considering was using a service account with domain-wide delagation, but I don't if it's possible to do what I want with it. Any ideas would be helpful.
This is a little advanced, but fesable.
You need to use the Calendar API with a service account and domain-wide delegation and OAuth2. I have described the process in this story on Medium (make sure to read through all three examples), however the steps are pretty much as follows:
Create a service account
Download its JSON key
Enable domain-wide delegation
Impersonate a super-user
Create token with OAuth2
Send request to the Calendar API with Bearer token generated with OAuth2

EWS Notification for Calendar Delegation

Is there any API to be notified that a user has delegated their calendar to my calendar? I would prefer an event I can subscribe to that would alert me that calendar their#account.com has delegated access to my#account.com
Is there any API to be notified that a user has delegated their calendar to my calendar?
No not directly in EWS you can subscribe to Folder level notifications https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/notification-subscriptions-mailbox-events-and-ews-in-exchange. However this will just tell you the folder has updated but not what on a folder has updated (eg in the case of delegation the permissions being changed etc.)
If you trying to capture Outlook Delegates (which is a different thing from somebody just going and assigning permissions to their calendar and or sharing externally) then because that also update the publicdelegate active directory property you can look at also event from Active Directory.
Also generally unless you have a real need for this to be realtime if you enable Mailbox auditing you will be able to also process this type of change by using the Audit logs. This method could also be used in conjunction with a notification to detect a certain type of change.

set room resource in Calendar App

My G Suite has room resources set and I can add resources to an event manually but not pro grammatically. I cannot find any reference in the documentation,
If you are using the CalendarApp service this is quite straightforward, rooms have IDs that are very similar to email adresses, you have to invite these ressources just as you would invite guests.
It comes as optional parameter in the createEvent method in the form of an array of email adresses.
You will find these adresses in the agenda of each of these rooms (properties).

How to select account in Google App Scripts for users with multiple accounts?

For users that are logged into multiple accounts, how can a script let the user pick an account? For example, Gmail, Google Drive, etc. provide a way for the user to select which account to use with a selectable option on the top-right of the page:
How can developers implement a similar mechanism?
There seems to be no way to do that with Google Apps Script libraries - GAS just uses the current primary account. Also, unfortunately, the API Client Library and thus Google Sign-In for websites don't work inside GAS web apps because of the sandbox frame. You could write your own or use some existing OAuth implementation to authenticate with Google but I found a much much simpler solution using Auth0 Lock with only a Google Connection (using the popup method because the redirect method doesn't work within the sandbox frame).
With Chrome Version 70.0.3538.102. You may resolve your issue (at least i did)
Now i make sure i ONLY signed in ONE account at a time. Then use "manage people"
if i have 3 google accounts, i will create 3 people and each time you only have 1 active google account session. With this setup, i ensured everytime my script only execute with my G Suite user instead of #gmail accounts
You can try using the Directory API to work with Apps Script. Retrieve the user using:
GET https://www.googleapis.com/admin/directory/v1/users/userKey.
You can then make an interface that displays the user accounts details(Name, email,etc).

Can one track the usage of a shared resource from google drive

Does anyone here know if you on Google Drive somehow can track if a public shared link to a file have been used?
That is, the resource have been downloaded, viewed or otherwise "touched"?
Yes, and no
No: For consumer accounts.
Yes: For within a domain for Google Apps unlimited account, you can using the Admin API to receive view events.
Find the documentation here: enter link description here, relevant except follows.
Retrieve Google Drive events by event name
To retrieve a report of all instances of specific event type such as creating or editing a document, use the following GET HTTP request using the authorization token described in the authorization documentation. The userKey is the primary email address of the user in the report. The eventName can either be a access or acl_change event. For the eventName information, see the Drive event names reference information. For more information about the request's query strings and the response properties, see the API Reference. For readability, the following example is formatted with line returns:
GET https://www.googleapis.com/admin/reports/v1/activity/users/all
/applications/drive?endTime=a date&startTime=a date
&filters=event name parameter relational operator parameter value,...
&actorIpAddress=user's IP address
&maxResults=maximum number of events returned on a response page
&eventName=either a view or edit event