Forum Discussion

kaarthick's avatar
kaarthick
New Member
7 years ago

power bi dataset refresh from databricks

Hi,
I'm trying to refresh the powerBI dataset from data bricks. The report data is from databricks in a direct query mode and we dont want to use the username password.

I'm using the sample code from MS site.

def authenticate_client_key():
authority_host_uri = 'https://login.microsoftonline.com/'
resource_uri = 'https://analysis.windows.net/powerbi/api'
api_url = 'https://api.powerbi.com'

tenant = 'My tenantID'
authority_uri = authority_host_uri + '/' + tenant
client_id = 'service principle Id'
client_secret = 'service principle key'

context = adal.AuthenticationContext(authority=authority_uri,
validate_authority=True,api_version=None)
mgmt_token = context.acquire_token_with_client_credentials(resource_uri, client_id, client_secret)

mgmt_token =mgmt_token.copy()
if "expiresOn" in mgmt_token and "expiresIn" in mgmt_token:
mgmt_token["expiresOn"] = mgmt_token['expiresIn'] + time.time()


ast = {re.sub('([a-z0-9])([A-Z])',r'\1_\2',k).lower(): v
for k, v in mgmt_token.items()}

return ast

creds = authenticate_client_key()

groupid = 'my groupid'
groupsPath = 'groups/'+groupid
datasetid = 'my datasetid'
uri = 'https://api.powerbi.com/v1.0/myorg/'+groupsPath+'/datasets/'+datasetid+'/refreshes'

bearer_token = 'Bearer ' + creds.get("access_token")
header_gs = {'Authorization': bearer_token, 'content-type': 'application/json'}
r = requests.post(uri,headers=header_gs)


I'm geting the token but the still getting the response 401 error. I can refresh the dataset manually in the powerbi site but when I try to refresh using API it is not working.

The principle account is having all access to power Bi and it is configured based on MS document.


Thanks,
Kaandy

No RepliesBe the first to reply