Forum Discussion
pbimdland
7 years agoRegular Visitor
Embed Token API Error: Creating embed token with multiple identities is not supported
Hello everyone, I am creating a dashboard in a web application via App Owns Data. I am able to follow this guide and embed my dashboard to the web application: https://docs.microsoft.com/en-us/po...
jayvandenbos
6 years agoFrequent Visitor
Hi,
I got the same error and contacted the Microsoft Power BI support team and they helped me out. Turns out there was something wrong with my request.
I'm creating an App owns data web application in Python Django and this is what works for me.
import requests
import json
username = '...'
password = '...'
client_id = '...'
report_id = '...'
group_id = '...'
dataset_id = '...'
settings = {
"accessLevel": "View",
"identities": [
{
"username": "Andrew Ma",
"roles": [ "Manager" ],
"datasets": [ dataset_id ]
}
]
}
data = {
'grant_type': 'password',
'scope': 'openid',
'resource': r'https://analysis.windows.net/powerbi/api',
'client_id': client_id,
'username': username,
'password': password
}
# Get access token
response = requests.post('https://login.microsoftonline.com/common/oauth2/token', data=data)
print(response.content)
access_token = response.json().get('access_token')
# Get embed token
dest = 'https://api.powerbi.com/v1.0/myorg/groups/' + group_id \
+ '/reports/' + report_id + '/GenerateToken'
embed_url = 'https://app.powerbi.com/reportEmbed?reportId=' \
+ report_id + '&groupId=' + group_id
headers = {'Authorization': 'Bearer ' + access_token, 'Content-Type': 'application/json'}
response = requests.post(dest, json=settings, headers=headers)
print(response.content)
embed_token = response.json().get('token')
print(embed_token)Turns out I forgot to add the Content-Type: application/json to the request headers. Also, my settings weren't formatted as json in the request.
Hope this helps you out.
Regards