Power bi Refresh Locally Rest API

Hi Dmitry

I watch this video on Call any Power BI REST API with PowerShell
https://youtu.be/YBTQ3CFstzs.
Datasets - Refresh Dataset In Group - REST API (Power BI Power BI REST APIs) | Microsoft Docs

I tried the following:

  1. Created a web location connector - https://app.powerbi.com/
  2. Use a web request
    POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshes

It did not work.
Is it possible?

Power Bi Premium Workspace

Thanks

Hi Rykie,

No need to do this via the API. We have a dedicated action for that. Use “Refresh dataset” in the “Power BI Command” action. See also: transformations:powerbicommand [EasyMorph Help]

Thanks, Dmitry.
With regards to Power Bi Connector, it needs approval.
image

And it is taking a long time.

That is why I looked at something else

In order to access Power BI REST APIs you need an access key, and to obtain it you have to create a custom application in the Power BI Developer’s portal and add it to your organization (and that would require the same admin approval), then you can begin to setup OAuth and craft and parse all responses manually...

I think waiting for admin approval is the best approach here.

1 Like

Thanks

Hello Dmitri,

Is it possible to create a PBI connector to run all other API commands ?

image

image
Can I find some documentation on that ?

I notice the native Power BI connector only has a few (very handy:)) commands

image

Thanks in advance

Hi Laurens,

Setting up custom OAuth authentication with Power BI can be pretty tedious because Azure is quite complex and requires some choices to make that are specific to your organization and its Azure setup. The process can be especially tedious if you are stuck at the very beginning of it.

First, of all you need to register an AD application, as explained here:

And here:

There you can get Client ID and Client secret.

Once you get to this point, let me know and I or someone else from our team will post further instructions.

Alternatively, write what API functions you need and we’ll see if we can quickly add them to the “Power BI command” action.

Hi Dmitry,

Thanks, as usual, for your willingness to help.
Well, we have a complete working setup with AAD and Power BI apps / datasets. Now is the time to get data, and especially usage metrics, from our PBI environment via the PBI Rest API.

I can already get data from the API via powershell and Postman, they use respectively a builtin PS function (Connect-PowerBIServiceAccount -Credential) and the usage of a bearer token.

While I found some information regarding certain mandatory fields like Redirect URI, Client ID, and Client Secret here: [
OAuth 2.0 client credentials flow on the Microsoft identity platform - Microsoft Entra | Microsoft Learn], I’m still uncertain about the Token URL.
Do you already have examples where this was successfully set up using the web connector?

You are right that the initial setup can be tedious, especially when everything is working well and they decide to enforce OAuth v2.0 ( eg :slight_smile: )

I really appreciate the proposal to expand the “Power BI command” action. However, I personally would like to have the flexibility to create custom PBI Rest API commands. Integrating and maintaining >100 commands in the “Power BI command” action could become challenging.

I believe this information will be useful for others as well.

Thanks again for your support.

PS: sorry, should have made a new forum topic

Hi @laupie

First, let me mention that internally we don't actually use OAuth when interacting with Microsoft services. Instead, we use MSAL, which works a little bit differently.

Secondly, based on the link you shared, it seems like you are looking to implement the 'client credential' grant flow. This is a non-interactive OAuth flow where you exchange the client_id and secret for an authorization token. Am I correct in understanding this?

Our Web Location connector's OAuth section actually implements a different flow called the 'Authorization Code Flow', which is interactive. If the 'client credential' flow is available in your environment, you should use it, as it is simpler and doesn't require Redirect URI at all.

With this flow, you exchange IDs for a token in a single POST request to the https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token endpoint, where {tenant} should be replaced with your tenant.

Here is the detailed explanation how to authorize using client credentials flow:

You just need to tweak connector from example a little, to make sure the POST request points exactly to https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token, something like this: