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

2 Comments
BEFORE WE START, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

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

 

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

  1. Hi
    Thanks for the article. I am facing a issue with this.
    This works for me and only shows the dataset in the workspace of the singed in user.
    I am trying to use this URL to get the dataset in another workspace.
    https://api.powerbi.com/v1.0/myorg/groups//datasets
    Do you know how to get this working? The user is Azure AD user so how can i give access on Power BI workspace to this Azure AD user as this does not come on the list when i try to add this user as a member.

    Thanks
    Naresh

Leave a Reply

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