Forum Discussion
Embedding report in external app with non-Power BI users
- 9 years ago
1. The registered Azure APP doesn't have anything to do with Power BI reports except to get the accesstoken. If you want to embed your reports in an external application you have to publish it to PowerBI service,
2.You could get the accesstoke and embedded token via two REST APIs as below.
--get the access token POST /common/oauth2/token HTTP/1.1 Host: login.windows.net Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded client_id=49dxxxxxxxthe register app client idxxxxx0-6d93f770d1a4&grant_type=password&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi&username=yourpowerbiaccount&password=yourpowerbipassword
--To get the embedded token for a report/dashboard/tile
--reference https://msdn.microsoft.com/en-us/library/mt784614.aspx
POST /v1.0/myorg/groups/dc5811-YOURGROUPID-f16b6c15/reports/16d21d5a-YOURreportID--46a2fd9/GenerateToken HTTP/1.1
Host: api.powerbi.com
Content-Type: application/json
Authorization: Bearer theTokenFromPriorAPI
Cache-Control: no-cache
{
"accessLevel": "View"
}3. Yes, it needs a Premium licence if you want to use Embedding with non-Power BI users (app owns data). For cost-saving, a more simpler approach would be using Publish to web, you don't have to apply option 1&2.
The first api returns the AccessToken and the RefreshToken, everything works fine...
But, when i use the second API, to generate the Embed Token, i get this message:
{"error":{"code":"BadRequest","message":"Bad Request","details":[{"message":"'request' is a required parameter","target":"request"}]}}
My app is full permissions to the access token retrieved from the AzureAD, and the reportId/datasetId i got from:
$.ajax({
type: 'POST',
url: `https://api.powerbi.com/v1.0/myorg/groups/${this.groupId}/reports/${this.reportId}/GenerateToken`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${this.authToken}`
},
body: {
"accessLevel": "View",
"datasetId": this.datasetId
},
success: (data) => {
console.log('ss', data)
},
error: (data) => {
console.log('rr', data)
}
});Are you trying to call this API from a browser?
It was not working for me - I think it was not working because server doesn't send access-control-allow-origin header
I wrote a Java client to REST API and used it to obtain tokens.
You can also run it from JavaScript but on the server side, not from the browser.
- sergio1708 years agoRegular Visitor
Yes!
i'm trying to call the api from a browser (and from Postman too)
Thanks for your answer! Now i'm getting another error:
{"error":{"code":"PowerBIEntityNotFound","pbi.error":{"code":"PowerBIEntityNotFound","parameters":{},"details":[]}}}
I've made everything step by step... and i have the PowerBI Pro account... My AzureAD, like i said, have all needed permissions and works as expected (giving me the access token).
Do you know what it can be?
- mda8 years ago
Advocate I
Unfortunately, I have no idea.
- pzielinski8 years agoRegular Visitor
Did you solve the problem? Because I am facing same issue