Microsoft Flow is the new workflow engine from Microsoft. With flow you can create automated workflows between your favorite apps and services to get notifications, synchronize files, collect data, and more.
You can find Microsoft Flow at: http://flow.microsoft.com
Flow contains many predefined templates to use: https://flow.microsoft.com/en-us/templates/. Things like send reminders via the Flow mobile app to you phone when you get a mail or sync your Dropbox files with OneDrive, …
The real power of Microsoft flow is the fact that you can use you own services and extend your flows with custom data. In the following demo I will create a flow to send a notification email to users from a custom REST web service.
To start I create a custom C# ASP.NET WebApi application in Visual Studio 2015. I called the application “SwaggerDemo“.
If you don’t want to create it yourself, you can download the solution from my GitHub account.
The Api contains the following code:
In the old days we created soap based web services that used WSDL to describe the service. Nowadays we use Swagger.io to do this. It is pretty easy to implement Swagger to an existing WebApi.
Use NuGet to add the Swashbuckle package to you project.
To know more about this, check this page: http://devcenter.wintellect.com/paulballard/give-your-rest-apis-some-metadata-swagger!
When you run your project now you get to see the “Swagger” output:
Now you can deploy your server to a public webserver and we can start using it with Flow.
To start using the Api we need to create a new service in Flow. Services are used to provide you the data and do operations.
To add your custom API, go to the Flow dashboard via http://flow.microsoft.com and click the settings icon in the top right corner:
Select “Custom API’s” and click the “Create custom API” button in the next screen.
To add an API you need a Swagger file, a JSON file that describes you service. To get the Swagger file for you WebApi go to http://editor.swagger.io, click “File” and “Import URL…”. Enter the url of you webapi in the next screen.
Click on “Import”.
Now you click “Download JSON” in the “File” menu:
Save that file because we’ll need it in a moment.
We go back to our Flow – Create Api screen and upload our Swagger JSON file and enter the details for our custom API:
That is pretty much all we need to do to register our Api in Flow.
No we can start creating our first custom flow in Microsoft Flow. Click on “My flows” in the top menu bar and click on the “Create from blank” button.
Start with giving you flow a name on top of the screen and add the first action. I added the “Recurrence” action to run my flow every 10 minutes for example.
In the next step I will call my custom service. Click on “Add action” and select your service. Mine was called Swagger DEMO:
You don’t need to do a lot of things here. The API will be called and the results will be stored in a some variables that we will use in the next step.
In this example I’ll send an email to each user I get from the service. I use the “Apply to each” action to iterate the results:
The output of the REST call to my custom service is stored in the “body” variable. The “Apply to each action will loop all the results and will execute each action in the container. I add a “Send an email” action to it.
The Swagger file that I uploaded while creating my custom service will provide me the objects and properties that I can use in my action. In this example I get an email address and a name for each user that the service call returns.
Now my flow is ready. All I need to do is save and publish it!