Connecting to APIs with Flow

Microsoft Flow makes it very easy to connect to many data sources, including web APIs for data analytics. You will need an API key to connect to APIs such as Facebook or YouTube. An API key is basically a password that is passed through with your HTTP request that authenticates your access to the API. In the example below, we’ll use YouTube as an example for connecting to an API with Flow.

Note: At the time of this writing, the HTTP action required for these instructions is a premium Flow feature.

First, create and name a new scheduled Flow. Set a recurrence interval that suits your needs. Click New Step, then search for the HTTP action.

Use GET for the method, and paste your URI. You can paste any YouTube channel ID including your own, but you’ll need to create an API key in order for this to work. The example below will provide you with basic statistics for any YouTube channel you specify:

https://www.googleapis.com/youtube/v3/channels?part=statistics&id=[CHANNEL_ID]&key=[API_KEY]

Replace [CHANNEL_ID] and [API_KEY]. In the end it should look like this:

At this point Flow won’t be able to identify the data returned into dynamic content you can use later on. So you need to use the Parse JSON action to tell Flow how your data is structured. Click New Step and search for the Parse JSON action, then select it. The Dynamic Content area will show up once you click the Content box, then select the Body from the previous HTTP request.

The Parse JSON action needs a data schema, but this is easily generated using the built-in tool. First, copy and paste your URI from the previous HTTP request step into your web browser. This should generate data that looks something like the example below.

Copy all the text and go back to Flow. (If you are using Firefox, you might need to click Raw Data before you can select the results.) Click Use sample payload to generate schema, paste the data you previously copied, then click Done.

Now Flow will know how your data is structured and results will be correctly labeled in following actions. At this point your Flow should look like this:

Once you run this Flow you’ll be able to access the values returned from the source API. I used the Compose action below to show an example of the data you can now access once the Flow runs. You can get the view count for the channel specified, for example. This can be loaded into many data sources, including Excel spreadsheets, SQL server, PowerBI datasets, and more. The possibilities are endless.

If you have API requests that return large datasets you might notice that a token is returned for the next page of data. In a future post I’ll demonstrate how you can page through JSON data and dynamically create new requests for each new page token.