How to Authenticate and Use the Power BI API inside Power Automate

Leave a comment

The Power BI API contains several useful pieces of functionality if you need to do interact with Power BI at a lower API level. Power Automate provides great automation features, and it’s only natural we would want to use the two together. Power Automate does have a Power BI connector, but we can get right to the Power BI API to unlock more features as well. Let’s look at how we can use the Power BI API within Power Automate.

First, we will need to register a new Azure App for Power BI.

Once that’s done, let’s log into Power Automate at https://flow.microsoft.com and create a new Instant Flow, as a Manually triggered flow:

We start with a Manually trigger a flow. Let’s add another action, HTTP:

We will provide the following:

  • Method = POST
  • URI = https://login.microsoftonline.com/common/oauth2/token
  • Headers: Content-Type application/x-www-form-urlencoded
  • Body: Replace the bold below with your information:
    grant_type=password
    &username=your@email.com
    &password=yourpassword
    &client_id=your client id from the Azure app you create above
    &client_secret=your secret from the Azure app you created above
    &resource=https://analysis.windows.net/powerbi/api

After running this, we see we’re getting the output with our Bearer access token:

Now, let’s get this access token. Copy the Body from above and create a new Parse JSON action, then click Generate from Sample:

Paste this into the JSON Payload sample and click Done:

We see the schema has now been built for us:

We can now use the Bearer to connect to the Power BI API. Create another HTTP action:

We will perform a simple GET operation to get Power BI datasets. The URL for this is https://api.powerbi.com/v1.0/myorg/datasets. For the Headers, add:

  • Authorization = Bearer <paste the access token from Dynamic content>

Now run the flow. We will test it manually:

We can see it ran successfully:

The output we get it datasets from Power BI. This was a simple example, you can also loop through the results, find multiple datasets, etc:

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *