dx_over_dt
dx_over_dt

Reputation: 14318

What do I place as the report id in the PowerBIEmbed when creating a new report?

I'm trying to use the PowerBIEmbed React component to create and design a new report. Everything works great when I edit an existing report, but when I'm creating a new one (using an embed token generated with TokenAccessLevel.Create), I'm getting the following error:

Report id is required, but it was not found. You must provide an id either as part of embed configuration or as attribute 'powerbi-report-id'.

The id I'm passing in via the configuration is the empty GUID ("00000000-0000-0000-0000-000000000000"). I have also tried deleting that property from the configuration.

I have the permissions set to models.Permissions.All (which includes models.Permissions.Create), so that isn't the issue.

Client code

const config = {
  permissions: models.Permissions.All,
  tokenType: models.TokenType.Embed,
  type: 'report',
  embedURL: generatedURL,
  accessToken: generatedToken,
  viewMode: models.ViewMode.Edit,
};

return (
  <PowerBIEmbed
    embedConfig={config}
    getEmbeddedComponent={report => this.setState({ report })}
  />
);

Server Code

var authToken = await PowerBIAuthentication.DoAuthentication(_Config);
using var client = new PowerBIClient(new Uri(_Config.ApiUrl), authToken);
var dataSets = await client.Datasets.GetDatasetsInGroupAsync(_Config.WorkspaceId, cancellationToken);
var dataSet = dataSets.Value.First(x => x.Name == "AppProtoModel");

var embedTokenParameters = new GenerateTokenRequest(TokenAccessLevel.Create, dataSet.Id);
var embedToken = await client.Reports.GenerateTokenForCreateInGroupAsync(
  _Config.WorkspaceId, 
  embedTokenParameters, 
  cancellationToken: cancellationToken);

myDoc.PowerBISettings.EmbedToken = embedToken;
myDoc.PowerBISettings.EmbedUrl = dataSet.CreateReportEmbedURL;

return myDoc;

Upvotes: 0

Views: 1819

Answers (1)

Pawan Karkal
Pawan Karkal

Reputation: 141

Currently, PowerBIEmbed component from powerbi-client-react library does not support create mode embedding for Power BI Report and, it can be achieved using Power BI JS SDK.

Refer below code snippets:

const embedConfiguration: IEmbedConfiguration = {
   permissions: models.Permissions.All,
   tokenType: models.TokenType.Embed,
   type: "report",
   embedUrl: createReportEmbedURL,
   accessToken: createEmbedToken,
   viewMode: models.ViewMode.Edit,
   datasetId: datasetId, 
};

const report = powerbi.createReport(reportContainer, embedConfiguration);

createReportEmbedURL mentioned in above snippet can be generated using Datasets - Get Dataset API. createEmbedToken mentioned in above snippet can be generated using Embed Token - Report GenerateTokenForCreateInGroup API.

Note: The datasetId passed in the configuration should be the same which is used to generate createReportEmbedURL.

Refer following docs for more information: Create and save embedded report

Upvotes: 4

Related Questions