Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
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:
Does anyone have any idea what I might be missing? Thanks.
@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?
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.
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.
User | Count |
---|---|
10 | |
5 | |
4 | |
4 | |
3 |
User | Count |
---|---|
14 | |
9 | |
5 | |
5 | |
4 |