Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
sergio170
Regular 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
Eric_Zhang
Employee
Employee


@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

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... 

I have same issue:

 

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

 

anyone?

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 

 

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); } } ); }

 

 

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors