I would try the Power BI API.
So I start by getting Embed Token ( I'm using application owns data scenario ).
1.access Token
var options = {
'method': 'POST',
'url': `https://login.microsoftonline.com/${process.env.TENANT_ID}/oauth2/token`,
'headers': {
'Content-Type': 'multipart/form-data'
},
formData: {
'grant_type': process.env.GRANT_TYPE,
'client_id': process.env.CLIENT_ID,
'client_secret': process.env.CLIENT_SECRET,
'resource': process.env.RESSOURCE,
'Scope': process.env.SCOPE
}
};
// get Access token from AAD to retrieve Embed Token in PBI API
let response;
try {
response = await new Promise((resolve, reject) => {
request(options, (error, response, data) => {
if (error) reject(error)
else resolve(data)
})
})
}
catch (error) {
context.error(error)
}
2.Fetch embed Token (Docs)
var data = '{accessLevel:"View"}';
var config = {
method: 'post',
url: `https://api.powerbi.com/v1.0/myorg/groups/${process.env.GROUP_ID}/dashboards/${process.env.DASHBOARD_ID}/GenerateToken`,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${JSON.parse(response).access_token}`
},
data: data
};
const embedtoken = await axios(config)
context.res = {
// status: 200, /* Defaults to 200 */
body: embedtoken.data
};
3. I have delegated permissions on azure
I'm getting an embed token.
4. fetch dashboard infos
I'm using postman to fetch dashboard infos from the same group id and dashboard id that I mentioned in the api to get embed token
( I add that token in authorization section )
The problem is that I'm getting 403 Forbidden error.
PS: In this post some limitations of service principal method are mentioned . is it the source of my problem ? Am I obliged to use master user
method ?
You have a misunderstanding of the usage of Embed Token. It cannot be used to call
https://api.powerbi.com/v1.0/myorg/groups/{group id}/dashboards/{dashboard id}/
directly. AAD token is needed here.To use an Embed Token, you should call the Embed URL with it.
The format of Embed URL is like:
An .net example:
Then you can call the
EmbedUrl
withEmbedToken
.Reference here.