Using Teamup REST API for Automated Reminders — An Implementation with Windows Powershell
This is a guest 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.
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.
Being 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.
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
Programmatically reading each event and preparing the email body
Now 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.
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 %
— — — — — — — —
Alias % -> ForEach-Object
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).
Originally published at blog.teamup.com on Feb 18, 2016.