In many enterprises, there is no piece of real estate more scarce than an unoccupied conference room. With so much importance placed on conference rooms, their rigorous management is critical to a successful Google Apps deployment.
While Google Calendar offers a flexible system for reserving conference rooms, projectors, scooters, or any other shared resource, it does not provide a documented API for creating, updating, and deleting resources. Instead, you must manually manage resources through the Google Apps control panel. Manual management may work for a small number of resources but becomes unscalable when managing thousands.
However, creative developers can find just such a Google Data (GData) API for provisioning resources. In this post, we’ll explore how to create, read, update, and delete calendar resources using GData through cURL, the commonly available command line HTTP client.
Discovering Calendar Resource support in GData.
Each type of entry in Google, whether a spreadsheet row, user account, or nickname has a collection URL. In true REST fashion, a GET request to the collection URL will return a list of entries. For example, an GET request to http://www.google.com/calendar/feeds/default/private/full will return a feed of calendar event entries. Likewise, a POST to this URL will add a new event entry to a calendar. So, to retrieve and create resources, we first need to discover the collection URL for calendar resources.
A calendar resource has many of the same characteristics as a user. For example, a calendar resource can be a meeting attendee and can be browsed by clicking “check guest and resource availability” in the Calendar user interface. Also, a calendar resource isn’t tied to a particular user when it is created. It is reasonable to believe that managing calendar resources through the API might closely mimic managing users through the provisioning API.
In the provisioning API, the collection URL for user accounts looks like this: https://apps-apis.google.com/a/feeds/domain/user/2.0. What if we change user to resource resulting in a URL like this: https://apps-apis.google.com/a/feeds/domain/resource/2.0? The example below uses the cURL application to send a GET request to the new URL. For details on using cURL with GData, see Google’s documentation.
curl -s -k –header “Authorization: GoogleLogin auth=DQAAAH4AA” https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0 | tidy -xml -indent -quiet
xmlns:openSearch=”http://a9.com/-/spec/opensearchrss/1.0/” xmlns:gCal=”http://schemas.google.com/gCal/2005″ xmlns:apps=”http://schemas.google.com/apps/2006″ xmlns:gd=”http://schemas.google.com/g/2005″> https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0 1970-01-01T00:00:00.000Z term=”http://schemas.google.com/apps/2006#resource”/> type=”application/atom+xml” href=”https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0″/> type=”application/atom+xml” href=”https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0″/> href=”https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0″/> 1 https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0/-81411918824 1970-01-01T00:00:00.000Z term=”http://schemas.google.com/apps/2006#resource”/> Bldg 3, room 201 href=”https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0/-81411918824″/> href=”https://apps-apis.google.com/a/feeds/mydomain.com/resource/2.0/-81411918824″/> email=”email@example.com”>
We’ve found the collection URL for calendar resources! Now, we just need to determine the XML schema for an individual resource. A hour of trial and error results in the following schema:
Since Google already does a great job of explaining the GData API, this post will not repeat that information. Instead, you can use the collection URL and entry schema in the same fashion as the other GData APIs to create, read, update, and delete calendar resources.