How to analyze PowerBI logfiles automated using REST API with Logic Apps and Azure Log Analytics Workspace
By: Lukas Fuchs
Tags: Log Analytics, Logic Apps, Azure Monitor, Power Bi, Azure

Preconditions

You need an Azure Subscription and Azure AD (AAD) admin privileges. You need a PowerBI Service subscription and PowerBI admin privileges.

Step 1: Register PowerBI App within Azure AD

There are two possibilities to register your PowerBI App within Azure AD. The first is to use the native PowerBI GUI. The other is to use Azure AD Admin Panel (Described below the following subchapter) here you will have more control what is happening.

Please note: The following Steps need Azure Admin privileges. Make sure you have those permissions or you can give this instructions to an AAD-Admin within the organization.

Go tho the “App Registrations” Page in Azure Active Directory.

Select “New registration”

Register the app name with the name that fits for you. In my case I use “Azure Power BI Integration App”.

Choose the supported account types that will be allowed to access the app. In most cases the first selection applies. In some scenarios e.g.: if you are a consultant coming from a trusted AD tenant you would probably select the second option “Multitenant” for instance.

The Redirect URI we leave open by now. This information we will get at a later point in time from the custom logic app configuration.

Now you are redirected to the app settings page. At the top of the page you can see important information like

App Client ID -> Note the ID, we will use it later

-> Note the ID, we will use it later Tenant ID -> Note the ID, we will use it later

Head to “Certificates and Secrets” in this settings page.

Click the “+ New client secret”

Enter a description that allows you to remember for whats the secret for.

Enter an expiry date that fits for your case. (In my case I don’t want any surprises in one or two years)

Now you have generated a new secret that can be used. Make sure to note the Secret Value, we will need this later on.

You should now have the following values in hand:

App (Client ID)

Directory (Tenant) ID

App Secret Value

Now, we head to the point “API Permissions”. Click “+ Add a permission”.

Scroll down to the point, where “Power BI Service” is listet and select it.

See the PowerBI Service URL at the top? Please note it down, we will use it later!

https://analysis.windows.net/powerbi/api/

Select “Delegated Permissions”

Select your needed permissions (depending on the log file topics you want to investigate).

In my instance I just want to read everything and don’t need any write permissions.

Please note: there is one special permission on tenant level, as shown in this picture. If you select those permissions, you need to grant admin privileges.

Confirm by clicking “Add Permissions” and you should now see the following:

Please note: I experienced some problems in accessing PowerBI datasets from Logic Apps in the following steps, that can be fixed at this point. For this I needed to click “Grant admin consent”. You can keep it as and maybe come back to this point if you experience the same issues or fix it right away here by clicking “Grant admin consent”.

Now we leave this configuration area to create a custom logic app. Please use a separate window since we need to return later on to enter and configure the redirection URL that will be generated from the custom logic app.

Step 2: Create an Azure Logic App Custom Connector

In this step, create and deploy a new custom connector via the Azure Portal that later can be used for connecting the PowerBI REST Webservices.

To start. We add a new resource in the azure portal and type in “Logic Apps Custom Connector”, click it and hit the “Create” Button.

Here we use the defaults, give a meaningful name like “Logic_App_Custom_ Connector_PBI”, click “Review / Create” and wait for the deployment.

After the deployment, we open the EDIT mode of the Custom Connector, in the “1. General” tab stick with the default settings (REST, OpenAPI File, and the Standard Swagger JSON File)

In the part just below, if you like you can choose to upload an icon (optional). Give a meaningful description and use “HTTPS” as Scheme. The most important point here is to put “api.powerbi.com” as Host. You can stick with the standard Base URL “/”

Now head to the “2. Security” tab…

In the “2. Security” tab, make sure you enter the following information:

Authentication Type: OAuth 2.0

OAuth 2.0 Identity Provider: Azure Active Directory

Azure Active Directory Client ID: Here we use our App (Client) ID we noted down in the step above…

Here we use our we noted down in the step above… Secret: Here we use our Secret Value we noted down in the step above…

Here we use our we noted down in the step above… TenantID: common

common Resource URL: Here we use the noted resource url from the step abvove (https://analysis.windows.net/powerbi/api)

Here we use the noted resource url from the step abvove (https://analysis.windows.net/powerbi/api) Scope: openid

openid Redirect URL: This will be generated, once you hit the “update connector” button (this we will need later to configure the App in AAD app registration menu.

Now we hit the “Update connector” button that generates us the Redirect URL:

https://logic-apis-westeurope.consent.azure-apim.net/redirect

This value shoud be copied since we need it for the AAD app registration finalization later on.

Now we head to the next section “Definition” …

Here we add a new Action and define some general information about the API we want to use.

Here you can find the API documentaion if you have a special API in mind: https://docs.microsoft.com/en-us/rest/api/power-bi/

In my case I want to get the history of data set refreshes to see if everything is refreshed without any problems. So I navigate to https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/getrefreshhistory.

Here you will find the reference that is need to get the latest (top 1) refresh of a dataset:

Everything that needs to be done now is to click “+ Import from sample”, define “GET” according to the documentation and the URL defined by the documentation, then click “Import”.

Finally we get the variables directly mapped to the fields. Those we can define in the later logic app that calls this logic app.

Don’t forget to click “update connector” that your changes are saved.