Forum Discussion
How to use Power BI Rest API without GUI authentication (redirect uri)
- 10 years ago
You can use the user name and password flow that AAD supports. This 3rd party client library has an example: https://github.com/Vtek/PowerBI.Api.Client
Thank you skaratela for the most concise write-up yet on how to actually get access to the Power BI API. However I am still banging my head on the wall trying to simply get my groups listed in Postman. I have tried many iterations, including following your process exactly. In all cases I am getting a 403 Forbidden on API calls, even though I have can authenticate and get an access token.
I have tried a Web App in AAD using a client_secret and grant_type=client_credentials; I have tried a Native App using grant_type=password (because AAD Native apps no longer give you a client_secret to work with). I have my master account as the owner of both AAD apps, and full Power BI API permissions granted to them.
My most recent authorization call/response looks like this, using an AAD Native App owned by my master account as the Client:
POST to https://login.windows.net/{{tenantId}}/oauth2/token
{
"grant_type":"password"
"client_id":"xxxxxxxxxx"
"resource":"https://analysis.windows.net/powerbi/api"
"username":"[email protected]"
"password":"xxxxxxxxxxx"
"scope":"openid"
}RESPONSE:
{
"token_type": "Bearer",
"scope": "Capacity.Read.All Capacity.ReadWrite.All Content.Create Dashboard.Read.All Dashboard.ReadWrite.All Data.Alter_Any Dataset.Read.All Dataset.ReadWrite.All Group.Read Group.Read.All Metadata.View_Any Report.Read.All Report.ReadWrite.All Tenant.Read.All Workspace.Read.All Workspace.ReadWrite.All",
"expires_in": "3599",
"ext_expires_in": "0",
"expires_on": "1520882770",
"not_before": "1520878870",
"resource": "https://analysis.windows.net/powerbi/api",
"access_token": "...",
"refresh_token": "...",
"id_token": "..."
}Then I take that access_token, and use it to try and get my groups:
GET https://api.powerbi.com/v1.0/myorg/groups
Authorization: Bearer {{access_token}}And I get a 403 error. Same result when I make the initial token request using an AAD Web App and providing client_id and client_secret parameters. Again, both my AAD apps have full Power BI API permissions granted, and are owned by my master account.
I have spent many hours struggling with this. Any help would be greatly appreciated.
Hi rogersmj
So it sounds like there is some permission problem and your request is being rejected - but you are getting the token back fine which is great!
Just one thing to note:
You mention 'I have my master account as the owner of both AAD apps, and full Power BI API permissions granted to them.' which makes me think perhaps you haven't bundelled your dashboard in a PowerBI App (and I don't mean a AAD app in this instance). Get your dashboard and put it in a PowerBI App and make that PowerBI App owner the same master account that you used for the AAD Apps. This is done through the PowerBI web portal (you should see 'Apps' on the left navigation pane.
Have you done this? - Let me know how you get on.
Shaheen