I've tried numerous times to register an app and connect to in in python:
app_id = '670...'
tenant_id = '065...'
client_secret_value = 'YJr...'
import requests
import msal
authority = f'https://login.microsoftonline.com/{tenant_id}'
scopes = ['https://analysis.microsoft.net/powerbi/api/.default']
app = msal.ConfidentialClientApplication(app_id, authority=authority, client_credential=client_secret_value)
result = None
result = app.acquire_token_for_client(scopes=scopes)
I feel like I've followed this video exactly: https://www.youtube.com/watch?v=3Fu8FjvYvyc&t=577s&ab_channel=JJPowerBI I'm up to minute 8:38.
I'm getting the following error messsage and googling it shows me the tenatid should be the id and not the domain name. I'm not sure why that's happening and what I need to change to get this to work
Edit adding API Permissions I am the owner of the subscription.
Edit2: Looks a little different then the comment, but I enabled this and it says it could take 15 minutes to update.
The error occurred as you are using wrong scope value to generate access token for Power BI API.
Initially, I too got same error when I tried to generate token with scope as https://analysis.microsoft.net/powerbi/api/.default
like this:
Make sure to use https://analysis.windows.net/powerbi/api/.default/ as scope value that worked and generated token successfully as below:
app_id = 'appId'
tenant_id = 'tenantId'
client_secret_value = 'secret'
import msal
authority = f'https://login.microsoftonline.com/{tenant_id}'
scopes = ['https://analysis.windows.net/powerbi/api/.default']
app = msal.ConfidentialClientApplication(
app_id,
authority=authority,
client_credential=client_secret_value
)
result = app.acquire_token_for_client(scopes=scopes)
if 'access_token' in result:
print(result['access_token'])
else:
print(result)
Response: