cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sergio170 Frequent Visitor
Frequent Visitor

Error to get EmbedToken to embed report in external app with non-Power BI users

Hi, 

 

I've looked this topic: https://community.powerbi.com/t5/Service/Embedding-report-in-external-app-with-non-Power-BI-users/td..., and followed the answer from Eric, he says to call 2 REST APIs.

 

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:

GET https://api.powerbi.com/v1.0/myorg/reports wich means that i have all permissions needed with the access token!
 
My request, with JQuery, from https://msdn.microsoft.com/en-us/library/mt784614.aspx wich Eric mentioned into his answer:
 
$.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)
}
});

 

What can be the error? 

If someone can help me, I would appreciate it.

5 REPLIES 5
Moderator Eric_Zhang
Moderator

Re: Error to get EmbedToken to embed report in external app with non-Power BI users


@sergio170 wrote:

Hi, 

 

I've looked this topic: https://community.powerbi.com/t5/Service/Embedding-report-in-external-app-with-non-Power-BI-users/td..., and followed the answer from Eric, he says to call 2 REST APIs.

 

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:

GET https://api.powerbi.com/v1.0/myorg/reports wich means that i have all permissions needed with the access token!
 
My request, with JQuery, from https://msdn.microsoft.com/en-us/library/mt784614.aspx wich Eric mentioned into his answer:
 
$.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)
}
});

 

What can be the error? 

If someone can help me, I would appreciate it.


@sergio170

The GenerateToken API indeed works. The problem in your case is POST BODY missing. Based on my test, in JQUERY, when sending the GenerateToken POST request, try

 

$.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}`
},
data: JSON.stringify({
  "accessLevel": "View"
}),
success: (data) => {
console.log('ss', data)
},
error: (data) => {
console.log('rr', data)
}
});

For better troubleshooting, you can check the request headers and bodies in Chrome develop Tool(F12).

Capture.PNG

sergio170 Frequent Visitor
Frequent Visitor

Re: Error to get EmbedToken to embed report in external app with non-Power BI users

Yeah, i've already changed that... too much coffee in mind... 

But, 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? Do i really need a Premium account to move my app for production? "publish to web" is not an option, because reports will show very sensible data... 

pzielinski Frequent Visitor
Frequent Visitor

Re: Error to get EmbedToken to embed report in external app with non-Power BI users

I have same issue:

 

{
"error": {
"code": "PowerBIEntityNotFound",
"pbi.error": {
"code": "PowerBIEntityNotFound",
"parameters": {},
"details": []
}
}
}

 

anyone?

Highlighted
pzielinski Frequent Visitor
Frequent Visitor

Re: Error to get EmbedToken to embed report in external app with non-Power BI users

Ok I solved it. It seems like I didn't have access to data on which Power BI do report (inside Power BI application, because I use sample dashboard) when I created my own report with data which I HAVE access everythink start working 

droe1 Frequent Visitor
Frequent Visitor

Re: Error to get EmbedToken to embed report in external app with non-Power BI users

 

Can you clarify what you meant by using your own report instead of the sample dashboard? I get the same error that the more recent post mentioned: 

 

{"error":{"code":"InvalidRequest","message":"Only group admin can embed group content"}}

 

I've used the above jQuery solution (my version is below) because first, I was getting the same original error. Any suggestions are greatly valued. I know the access token is valid because I can do GET requests using the same way of obtaining the access token. Only on POST do I get the group-admin error message.

 

 

window.onload = function () {
    /* Test based on articles */
/* Access Token seems to work for doing GET requets */ $.ajax( { type: 'POST', url: "https://api.powerbi.com/v1.0/myorg/groups/{$groupID}/reports/{$reportID}/GenerateToken", headers: { "Content-Type": "application/json", "Authorization": "Bearer {$accessToken}" }, data: JSON.stringify ({ "accessLevel": "View", "datasetId": "{$datasetID}" }), success: function(data) { console.log('ss', data); }, error: function(data) { console.log('rr', data); } } ); }