Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
rsrwebsupport
Frequent Visitor

API Issues

I'm attempting to use PyPowerBi to access the API in Python and I'm hitting a lot of weird permissions issues.  I don't believe it's the fault of the Python library, but I mentioned it just in case.

 

I'm able to authenticate using https://analysis.windows.net/powerbi/api as the resource URL and then using my application's client ID and client secret.  This returns a token successfully.

 

When I attempt to use the token, that's where the issues occur.  If I hit https://api.powerbi.com/v1.0/myorg/groups to get a list of groups, it returns no groups even though I have one configured.  If I then hit the endpoint to get reports, I get an error that says "API is not accessible for application".

 

I have all of the following API permissions set for the user:

rsrwebsupport_0-1632151808097.png

Does anyone have any idea what I might be missing?  Thanks.

4 REPLIES 4
Anonymous
Not applicable

@rsrwebsupport PyPowerBI is not an official library. Any errors related to the use of this library is a question sadly needs answering from the owner of the code.

But i've used the following code to authenticate and call some dataset refreshes:

import adal
import requests
import json

#Aunthentication
authority_url = 'https://login.microsoftonline.com/<INSERT TENANT ID>'
resource_url = 'https://analysis.windows.net/powerbi/api'
client_id = '<INSERT CLIENT ID>'
client_secret = '<INSERT CLIENT SECRET>'
context = adal.AuthenticationContext(authority=authority_url,
                                     validate_authority=True,
                                     api_version=None)
token = context.acquire_token_with_client_credentials(resource = resource_url,client_id=client_id,client_secret=client_secret)
access_token = token.get('accessToken')

#Refresh Dataset
refresh_url = 'https://api.powerbi.com/v1.0/myorg/groups/<INSERT GROUP ID>/datasets/<INSERT DATASET ID>/refreshes'
header = {'Authorization': f'Bearer {access_token}'}
r = requests.post(url=refresh_url, headers=header)
r.raise_for_status()
print(json.dumps(r.text))



Thanks for the response.  I tried the code you posted, and it's able to authenticate and get the token, but the API call returns a 404, which is basically what I was seeing with PyPowerBi.  I was ultimately able to get it working by authenticating via the "acquire_token_with_username_password" function in ADAL and just using the account's username/password, but ideally we would use the client credentials to authenticate.  Can you think of any reason why the one authentication would work for the API but the other would not?

Anonymous
Not applicable

Not exactly sure, but i'm assuming there is a differnce between your acess credentials as user v/s the app.
The Microsoft documentation does mention the app to have 'ReadWrite.All' permission which is not visible in our screenshot above.

 

sbanda_1-1632235619253.png

 

Hope this helps.

 

I just tried adding all of the write permissions and it still didn't seem to make a difference.  One thing I did notice is that I'm able to hit the groups API with the client credentials authentication, but it returns no groups, whereas the username/password authentication returns the group as expected.  I'm assuming there's some setting somewhere that I'm missing, but I can't seem to find it.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors