Skip to main content

Create an Exchange Meeting Rooms API with Azure Functions


In this series of posts I am creating three Azure Functions to provide an API for use with PowerApps, via a custom connector, to display bookings from Exchange Online meeting rooms.

The Azure Functions described here were developed with Visual Studio 2017 using the Azure Functions Tools Add-in that provides an efficient way to create Azure Functions that can be developed and run locally before being deployed to Azure.

With the tools installed, create a new project using the Azure Functions template.


Once the project is created, right-click on your project in the Solution Explorer and choose Manage NuGet Packages. Search for and install the Microsoft Exchange WebServices package.




Create three C# class files, copying the code below (rename the namespaces as appropriate for your project).

GetRoomLists.cs
This gets the list of meeting room lists, which group meeting rooms by, in our case, campus. This function takes no parameters.

Rooms.cs
This provides a list of rooms per room list. It takes only one parameter - the address of the meeting room list (e.g. campus_a@mydomain.com).

Note: for this function, I added the "/list" to the end of the route. This was because I was passing in the full email address of the room list as a parameter in the URL, which Azure Functions currently has issues with. This could have been changed to just pass in the name part of the email address (and then inside the function add on the domain part).

GetRoom.cs
This returns a list of bookings for the room on the specified date. It takes the email address of the meeting room along with the year, month and day we want to view the appointments for.

As can be seen above, the routing template gets matched to the parameters in the method signature.

The functions above rely on the fact that we have a service account (that is, a regular account not tied to any one person) with the necessary permissions to view the meeting room bookings. When developing locally, the username and password are stored in the local.settings.json file you will find in your project.

Replace the username and password for the service account you created.

After publishing the functions to Azure from Visual Studio, several settings require configuration. Navigate to the Azure portal and access the functions you have just published.
Click on Platform Features.



In the CORS section, add https://web.powerapps.com.

In Application Settings, add the items for the username and password for your service account matching the key names and values from what you used in your local.settings.json file.

I also had to add a key of WEBSITE_TIME_ZONE and a value of (in my case) "AUS Eastern Standard Zone" so the booking dates came out as expected.

Next, grab the API key that will be used to secure the API.

Click on Settings and copy the _master key by clicking the Copy link. Stash this away somewhere to use later.



To allow PowerApps to access the API we need to create a Swagger definition that decribes the API.

Click on API Definition (preview). Then, click Generate API definition template which will give us most of what we need.

For each of the functions described in the Swagger file, we need to make some changes.

First, each function needs in the 'parameters' section a default parameter named 'code' that will include your API key in each request - for the GetRoomLists function you will have to include the 'parameters' line as well, but the other two functions will already have it (as they have parameters, which the auto-generation step picked up).

Second, change the value of the 'operationId' field to something more straight forward (PowerApps will complain later if it is not), and add in a 'summary' field summarising the function.

Finally, we need to describe the output of each function in the 'responses' section to define the array of JSON objects that is produced. The final file should look similar to:

Remember to ensure the tab indenting is correct or the YAML file will not save. Also replace the [..your API key here..] with the API key you copied earlier.

Now click the Export to PowerApps and Flow button. Choose Express as your export mode, choose your environment (typically the Office 365 domain you are using PowerApps with), give your API a name and click OK.

To verify that the connector was created, browse to https://powerapps.microsoft.com and sign-in.
Click on Connectors from the left-hand navigation and then click Manage custom connectors.


You should be able to see the connector that was exported in the list.


In the next post, we'll use the connector to create our PowerApps app.

Comments

Popular posts from this blog

Create a Microsoft PowerApps App to View Meeting Room Bookings

In this series of posts I am creating three Azure Functions to provide an API for use with PowerApps, via a custom connector, to display bookings from Exchange Online meeting rooms.

IntroductionCreating an Exchange Meeting Rooms API with Azure FunctionsCreate a Microsoft PowerApps App to View Meeting Room Bookings (this post) In this final post of the series we will now use the Azure Functions API in the PowerApps app.
Open up PowerApps studio and create a new blank Phone layout.
On the first screen, drop in a rectangle shape (which is found on the Insert tab, under the Icons drop down) and position it into shape as a header. Add a label (set the colour white for contrast) and change the text to the name of your app.
Then, on the Insert tab click Gallery and choose Vertical.

Position it to take up the available width and height under the header. Give it a name, like 'RoomLists'.
With the control selected, from the properties pane choose the Title layout option.

From the Conten…

Using Microsoft PowerApps with Azure Functions to View Exchange Meeting Room Bookings

Microsoft PowerApps provides a large range of connectors to access data from external services. However, when the service you require is not there what options are available?

One recent scenario I had was to provide a display of the bookings in our organisation's meeting rooms on a given day. We use Exchange Online, as part of Office 365, to manage our meeting room calendars. I needed a way to connect to these meeting room calendars and present the information easily and quickly.

Happily, PowerApps provides the ability to define a custom connector allowing you to access a Web API which provides quite allot of potential.

Using Azure Functions, its possible to create an API that will expose details of meeting room lists (e.g. meeting rooms per building), meeting rooms for a given list and the bookings for a meeting room on a given day.

This API can be used with PowerApps, via the custom connector, to create the solution:



Over a series of posts, I will go through how to build the …