Share via


Using Microsoft Flow with Web Services to send messages to Microsoft Teams

In this blog post I'm going to explain how you can use Microsoft Flow to query a REST API Web Service and based on some conditions have a message send to Microsoft Teams.

Microsoft Flow Microsoft Flow is a product to help you set up automated workflows between your favorite apps and services to synchronize files, get notifications, collect data, and more.

To get started with Microsoft Flow you first to sign up, or, if you already have an account with Microsoft, you can directly sign in on your tablet, your desktop computer, or even your phone.

Microsoft Teams Microsoft Teams helps your team work better together. It’s one app that brings your team’s conversations, meetings, files, and notes together into a single place for open and seamless collaboration.

To get started go to the Microsoft Teams website. Keep in mind you need to have Office 365 to use Microsoft Teams.

Scenario

For the following scenario I expect you to have already created a Microsoft Team where Microsoft Flow can send it's message to. I you have not created a Team you can find information on how to create a Team here.

Back to the scenario we want to implement with Microsoft Flow and Microsoft Teams. At Microsoft NL we have a Parking App which shows the available parking spaces left. This helps to determine if we need to find another parking spot close by to our office at Schiphol Airport.

The web app is accessible via any browser. Besides available parking spaces it also shows some other information.

Screenshot Parking App

Because I don't want to open the web app each time when leaving home to verify if there are enough free parking spaces available I want to use the REST API service behind the web app and have a message being send to my Microsoft Teams Channel if there are less then 10 free spaces left.

Steps to implement the Microsoft Flow

  1. Log in to Microsoft Flow
  2. Create a new Flow and start with a blank template

New Flow

Search for the HTTP Connector and select this connector.

HTTP Connector

  1. Configure the HTTP Connector

Configuration

The method is GET and in the URI you enter the REST API endpoint from the Web Service you want to use.

  1. Add Parse JSON Action

Parse JSON action

Select the Parse JSON Action from the Data Operations Connector.

  1. Configure Parse JSON Action

Configure Parse JSON

Add the Body data coming from the HTTP Activity into the Content field in the Parse JSON Activity. And in the schema add the following:

 {
  "type": "object"
}
  1. Save the Flow and have it run.

Create Flow

If everything works ok you get some data returned from the Web Service.

firstrun

  1. Copy the body content from the first run.

Copy the body content from the first run (Go to Activity in Microsoft Flow)

Activity

Click on the Flow you just run.

Copy the content from the body to your clipboard.

body

The body content will be used in the Schema configuration of the Parse JSON activity.

  1. Change the Schema content of the Parse JSON activity.

Edit your flow and change the Schema content with the body content on your clipboard.

Select Use sample payload to generate schema.

generateschema

Copy and paste clipboard content to sample JSON Payload and click on Done.

You can now add a new step.

schemaupdate

  1. Add Condition Step

condition

Select choose a value and select FreePlace property.

We now continue to configure the Condition.

lessthan10 choosevalue

Go the IF YES component and add an action. Search for the Alert the Team action.

Alert the team

  1. Configure the Alert the Team action.

Make sure you have the Microsoft Teams Connection configured before continuing.

Enter Team Id, Channel Id and the message you want to send to the Teams channel.

Configure Alert the team

  1. Update the flow and enable the new Flow.

Check now the Flow Activities for your updated flow.

If your condition is met a Message should be send to Microsoft Teams. (I had to change the condition higher than 10 to have a message sent)

MicrosoftTeams

You can add some more advanced conditions or even schedule the Flow to run between some time span. It's completely up to you to change it according your needs.

Hope you enjoyed this blog post.