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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jawarren
Regular Visitor

Create Report in Embed View via Power BI API

I am trying to create a new report from a dataset in an embedded view. However, I keep getting "This content isn't available" and the reportEmbed.min.js returning a 403 on render. Within app.powerbi.com I can successfully create and save reports, but as mentioned above the embedded view is not working.

 

I am following this documentation exactly:

https://github.com/Microsoft/PowerBI-JavaScript/wiki/Create-Report-in-Embed-View

 

However, I am generating my embed token via a Power BI API call as documentation allows here:

https://msdn.microsoft.com/en-us/library/mt784614.aspx

 

Here is my server-side, embedToken generation code:

const createReportEmbedTokenForCreation = ({
  accessToken,
  groupId,
  datasetId,
}) =>
  new Promise((resolve, reject) => {
    const url = `https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports/GenerateToken`;
    const headers = {
      'Content-Type': 'application/x-www-form-urlencoded',
      Authorization: `Bearer ${accessToken}`,
    };
    const form = {
      accessLevel: 'Create',
      datasetId,
      allowSaveAs: true,
    };
    request.post({ url, form, headers }, (err, result, body) => {
      if (err) return reject(err);
      const bodyObj = JSON.parse(body);
      if (bodyObj.error) return reject(new Error(body));
      return resolve(bodyObj.token);
    });
  });

Here is my client-side embed code:

const config = {
  accessToken: embedToken,
  embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed',
  datasetId: defaultReport.datasetId,
};
const report = powerbi.createReport(
  document.getElementById('ReportEmbed'),
  config,
);

Am I missing some scope some where?

 

Thanks in advance!

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @jawarren,

 

Here is a similar thread in which some troubleshooting steps are mentioned. Could you go to check if it helps in your scenario? Smiley Happy

Power BI has a tile embed sample, which I verified works correctly with interactive user login. Note, that when you're using Power BI.com, the user needs to be an AAD user and needs to login as themselves for licensing reason.  As someone alluded to in another comment if you want to not use AAD users, you'd use Power BI Embedded, which doesn't require the end user to be an AAD user. 

 

https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-integrate-tile/

 

Can you use your client ID and secret with the above sample and see if it works.  Make sure the application has the following redirect URL configured:

Http://localhost:13526/

 

Usually, you get a 403 when the application does not have appropriate permissions. Remember that if you added permissions (scopes) to the application AFTER the user trusted the application, the user’s token won’t get the new scopes until they remove trust from the application and trust it again. Easiest workaround is to create a new application and use that instead.  Alternative is to manually remove the application using Office 365’s “my apps” feature and then try to use the application again.

 

You might also draw inspiration from several other similar threads from other services:

http://stackoverflow.com/questions/31735264/403-forbidden-from-azure-graph-api

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applica...

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-developers-guide



 

Regards

jawarren
Regular Visitor

I am trying to create a new report from a dataset in an embedded view. However, I keep getting "This content isn't available" and the reportEmbed.min.js returning a 403 on render. Within app.powerbi.com I can successfully create and save reports, but as mentioned above the embedded view is not working.

 

I am following this documentation exactly:

https://github.com/Microsoft/PowerBI-JavaScript/wiki/Create-Report-in-Embed-View

 

However, I am generating my embed token via a Power BI API call as documentation allows here:

https://msdn.microsoft.com/en-us/library/mt784614.aspx

 

Here is my server-side, embedToken generation code:

 

const createReportEmbedTokenForCreation = ({
  accessToken,
  groupId,
  datasetId,
}) =>
  new Promise((resolve, reject) => {
    const url = `https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports/GenerateToken`;
    const headers = {
      'Content-Type': 'application/x-www-form-urlencoded',
      Authorization: `Bearer ${accessToken}`,
    };
    const form = {
      accessLevel: 'Create',
      datasetId,
      allowSaveAs: true,
    };
    request.post({ url, form, headers }, (err, result, body) => {
      if (err) return reject(err);
      const bodyObj = JSON.parse(body);
      if (bodyObj.error) return reject(new Error(body));
      return resolve(bodyObj.token);
    });
  });

 

Here is my client-side embed code:

 

const config = {
  accessToken: embedToken,
  embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed',
  datasetId: defaultReport.datasetId,
};
const report = powerbi.createReport(
  document.getElementById('ReportEmbed'),
  config,
);

Am I missing some scope some where?

 

Thanks in advance!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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