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.
- Creating an Exchange Meeting Rooms API with Azure Functions (this post)
- Create a Microsoft PowerApps App to View Meeting Room Bookings
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).
This gets the list of meeting room lists, which group meeting rooms by, in our case, campus. This function takes no parameters.
This provides a list of rooms per room list. It takes only one parameter - the address of the meeting room list (e.g. email@example.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).
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 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.
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.
In the next post, we'll use the connector to create our PowerApps app.