Using Teamup REST API for Automated Reminders – An Implementation with Windows Powershell

Teamup Calendar for scheduling at a community of musicians

There is a community of musicians in the Pittsburgh area who get together on the first Friday of every month to play acoustic music.  The “Tunedown” travels to different host locations month to month. When the group was formed eight years ago, we had a basic email membership list for communication and I would coordinate the schedule. As the membership grew (currently 30 members), it became more difficult to manage the schedule.  I found myself having to send updated schedules more often, as folks would change plans, resolving scheduling conflicts, etc.

Calendar for community of musiciansBeing a Microsoft Powershell expert, I decided to utilize the TeamUp calendar REST API in conjunction with some Powershell automation to send email reminders and schedule to the folks in the mailing list.  Everyone in the email list receives an individual branded message which contains the modify link so that whoever would like to schedule a event can do so.  The informational pane to the left of the calendar contains all of the email addresses in the list. In case of a conflict, the other party can be contacted to resolve the conflict directly.  In addition, the email list is attached to the message as well as the official “Tunedown” logo.  The driving factor for using Teamup was the REST API, which enables these automated reminders to be sent.  The script also enables me to add a custom message, along with the Facebook Group link and TeamUp Calendar modify link. The script provides a good starting point for anyone who wants to work with Teamup Calendar events.  It should be viewed as foundation only, feel free to modify it to suit your needs. Extract the contents of the zip file to c:\teamup.  Open the text files and script and tailor to your environment.

Powershell reminder teamup

The script can be broken into three separate parts:

  • Initialization and enumeration of the Teamup calendar
  • Programmatically reading each event and preparing the email body
  • Looping through the list of addresses and submitting the email

Initialization and obtaining the events

Lines ten through twelve format todays date used for calendar query, the DNS name of the TeamUp service and the API key.  See the Teamup documentation for obtaining a key.  The Invoke-Webrequest cmdlet is a very powerful command that can issue GET and POST requests and pass credentials.  In this case we are using a token key, other uses would be to send Base64 encoded credentials over SSL or other authentication methods. Lines 16, 18 and 19 issue the call to the TeamUp REST API.  The result is returned as JSON, (JavaScript Object Notation) is a lightweight data-interchange format, based on a subset of Javascript.  Powershell can convert JSON data into a native Powershell Object easily using the convertfrom-json cmdlet (Line 19).  Lines twenty and twenty one create a collection of events pulled from the calendar and sorts them in ascending order by date.

Programmatically reading each event and preparing the email body

Reminder email sent from the calendarNow that we have the collection of events, we can use a foreach statement (line 29) to enumerate the collection and build our email message, lines 23 through 52. The “%” symbol is known as a powershell alias for the foreach keyword. If we run the script through the debugger, we can access any of the individual event attributes using dot notation. In this scenario, I was only concerned with the day that that the event is happening, not the details of start and end times. In line 26, there is a check for a custom message, which will appear above the schedule, separated with a horizontal rule. The powershell alias “gc” or get-content will read the contents of a custom message file stored in the c:\teamup folder.

Looping through the list of addresses and submitting the email

Lastly, lines fifty-three through 75 will open a list of email addresses exported from Outlook (line 55) and loop through them, sending the html formatted email to each recipient (Line 67).  The email list and logo are attached to the email from a declared array in line 56. Line 67 does the heavy lifting of submitting the email to an SMTP server.

Conclusion

Windows Powershell is a very powerful language and is perfect for accessing REST data sources across platforms.  In this example, we retrieved a set of calendar events, converted the data to a native powershell object and used a few loops to read the calendar events, construct and send an html formatted email. If my use of aliases in the script are confusing, run the get-alias command to see the full powershell statement (I have grown used to using the aliases).

Example: get alias %

CommandType     Name

———–     —-

Alias           % -> ForEach-Object

Download the zip file

Many thanks to the folks at Teamup for asking me to do a guest blog post.  This is my first public blog post, I hope that you find it useful!  Please feel free to contact me with any questions (Twitter: @CMU_robsmith).


This is a guest blog post by Rob Smith.  A Carnegie Mellon Systems Engineer, Rob has been working with Powershell for many years and uses it extensively for interfacing with REST and created general systems for automation and administration.  Two of his passions are coding in Windows Powershell and playing music.  Here is the story of how Teamup allowed him to more efficiently schedule monthly jam sessions while using his programming skills with Powershell.