Icon

A simple example demonstrating the use of a Transposit operation to get events from a Google calendar.


This is a very simple Transposit application to demonstrate a few basic functions.

  1. Start by viewing the app's code.
  2. Add a key for your Google calendar.
  3. Set the @calendarId parameter to the email address associated with one of your calendars.
  4. Run the get_calendar_events operation. In the Results tab, you should see some calendar event data returned in JSON format.

Now, go ahead and fork the app so you can make changes and customize it the way you'd like.

Constrain the time range#

In your newly forked app, let's see how you can constrain the time range of calendar data returned, by specifying a timeMin per the Google Calendar API. Suppose we want to see events that begin today onward, and we want to put them in a sensible order.

Take a look at the JavaScript operation today_date, with the following code:

(params) => {
return {
today: new Date()
};
}

Run this JavaScript operation and observe the JSON result.

Next, return to the get_calendar_events operation, and add three AND clauses:

SELECT summary, start FROM google_calendar.get_calendar_events
WHERE calendarId=@calendarId
AND timeMin = (select today from this.today_date)
AND singleEvents=true
AND orderBy="startTime"
LIMIT 5

Run the operation, and the calendar entries now returned should start no later than today.

Deploy the operation#

  • Click on Deploy > Endpoints in the left navigation.
  • Choose the get_calendar_events endpoint and set it to Deployed.
  • Check the Require user sign-in checkbox.
  • Click the Save button at the bottom of the page.

Require user authentication#

Next, let's set it up so when users try your app, they can bring their own credentials and access their own data.

Click on Authentication > Production Keys, and enable the Require users to authenticate with these data connections checkbox for google_calendar.

Use the operation in a hosted app page#

Click on Code > Page template to see the template for the hosted app page. Down around line 57 you'll see the operation get_calendar_events called.

Load the live hosted app (find your app's URL at Deploy > Hosted Page) and once you've signed in and supplied Google Calendar credentials, you'll see your calendar events there.

Anyone you share your app with can then supply their own credentials and see their own data.