Using the HTTP action to make requests with Microsoft Flow

Using the HTTP card in Microsoft Flow and referencing the output parmeters in conditions

Last week I blogged about how you can use a simple custom API to send yourself weather updates periodically. Custom APIs are very useful when you want to reuse custom actions across many flows. If your scenario requires using the action just in one flow, writing a custom API for that one action could be a bit of an overkill. In this blog post, we are going to look at using the HTTP card and how to use it within a flow.
Again for this blog post – I am going to use the weather example, this time though from openweathermap.org to get the weather information for Seattle, US. Then I am going to check whether it is going to rain or not using the condition card, and send myself a push notification only if it’s going to rain.
Looking at the openweathermap APIs you can see that we need to make a GET request with the URI (as shown) to get the weather for Seattle, US.

FTW_6

The response body like this –

{
  "message": "accurate",
  "cod": "200",
  "count": 1,
  "list": [
    {
      "id": 5809844,
      "name": "Seattle",
      "coord": {
        "lon": -122.332069,
        "lat": 47.606209
      },
      "main": {
        "temp": 294.49,
        "pressure": 1021,
        "humidity": 40,
        "temp_min": 292.04,
        "temp_max": 296.15
      },
      "dt": 1468619160,
      "wind": {
        "speed": 3.1,
        "deg": 230
      },
      "sys": {
        "country": "US"
      },
      "clouds": {
        "all": 75
      },
      "weather": [
        {
          "id": 803,
          "main": "Clouds",
          "description": "broken clouds",
          "icon": "04d"
        }
      ]
    }
  ]
}

Specifically, we are interested in the property that's highlighted, if the value of the "main" property contains the word Rain, then we want the flow to send a Push notification, if not – do nothing.

To reference the property we will need to use the advanced mode on the condition card, and set it up as follows :

@contains(body('Http')['list'][0]['weather'][0]['main']}', 'Rain')

Learn more about flow expressions here : https://msdn.microsoft.com/library/azure/mt643789.aspx

 

FTW_7

 

This flow, will now send me a push notification whenever it detects rain. You can play around with how often you'd like to receive these notifications or setup various other conditions. The HTTP card is a very powerful tool to quickly get a custom action into Flow.

NOTE: We have a limitation today, where expressions can only be used in the advanced mode on the condition card. The HTTP + Swagger action can be used in scenarios where you want to use tokens from the response body, much similar to Custom APIs, which I will cover in a future post.