Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 49039

Re: Embed Token API Error: Creating embed token with multiple identities is not supported

$
0
0

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


Viewing all articles
Browse latest Browse all 49039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>