1

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)

Overview: enter image description here

enter image description here

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

enter image description here

Edit adding API Permissions I am the owner of the subscription.

enter image description here enter image description here enter image description here

Edit2: Looks a little different then the comment, but I enabled this and it says it could take 15 minutes to update.

enter image description here

7
  • Could you include API permissions Portal image of your app registration by editing your question? Commented Nov 28, 2024 at 4:13
  • @Sridevi added the pictures Commented Nov 28, 2024 at 4:23
  • Could you confirm whether you allowed service principal access in your PowerBI Admin portal? Refer this if it helps stackoverflow.com/questions/77867783/… Commented Nov 28, 2024 at 4:25
  • And please confirm whether you are using any custom domain or tenant domain ending with onmicrosoft.com? Commented Nov 28, 2024 at 4:26
  • @Sridevi I added another edit. I believe I enabled service principals, says it could take up to 15 minutes to apply change. Commented Nov 28, 2024 at 4:39

1 Answer 1

2

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:

enter image description here

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:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.