Sunday, 24 November 2019

API Power BI Get token but get request get response 401

I have registered an APP in Azure to access PBI (with MFA); APP details: Native App (mobile desktop) API Permissions #Azure Active Directory Graph (1) User.Read #Power Bi Service (1) DataSet.ReadWrite.All I can get the token but when try to run a get request I get error 401.

import adal
import requests


authority_url = 'https://login.windows.net/<tennantID>'
resource_url = 'https://analysis.windows.net/powerbi/api'
target_url = 'https://api.powerbi.com/v1.0/myorg/groups/<groupID>/datasets'

client_id = '<applicationID>'
secret= '<clientsecretID>'

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=secret)

access_token = token.get('accessToken')

#print(access_token)


header = {'Authorization': f'Bearer {access_token}'}
#print(header)
r = requests.get(url=target_url, headers=header)
r

I expect to get a list of datasets on the group but getting error 401

HTTPError: 401 Client Error: Unauthorized for url: https://api.powerbi.com/v1.0/myorg/groups//datasets



from API Power BI Get token but get request get response 401

No comments:

Post a Comment