Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Create Report in Embedded Power BI with GenerateTokenRequestV2

Hi,

I have a powerBI embedded into a web application. The app contains a feature to create new reports as well that will save it into a workspace with the specified dataset.

The new experience workspaces came up with the dataset sharing capability, that'll enable users to create reports across multiple workspaces but using the dataset from one workspace. I've used the GenerateTokenRequestV2 to generate the embed token and used the Microsoft client library for JS PowerBI-Client to embed the same.

Am able to successfully embed and work on creating the report with the specified dataset, but there is an error thrown up on trying to save the report.
The network tab shows a call with endpoint "https://wabi-west.../explore/explorations?name={Report Name}" returning 403 status code.

 

Any help appreciated. Thanks in advance. 

10 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi V-lianl-msft ,

       

      The account is provisioned with Powe BI PRO license.

       

      I tried creating the report in the similar way (with shared dataset) in the power BI web app directly and it worked fine, but facing the issue when doing it via embedded mode in our web application.

       

      This is the config I send to the "powerbi-client" library.

      {
            type: 'report',
            tokenType: 1,
            accessToken: '__access_token__',
            embedUrl 'https://app.powerbi.com/reportEmbed',
            datasetId: '__shared_datasetID__',
            groupId: '__target_workspaceID__',
      }
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi V-lianl-msft ,

      The account is provisioned with PRO license but the workspace is under a dedicated premium capacity and the tenant runs under a Power BI Premium subscription.

      Is the Power BI Embedded license still required?

  • shietpas_cbts's avatar
    shietpas_cbts
    Frequent Visitor

    I am also experiencing this issue.  I am generating embed token using pbiClient.Reports.GenerateTokenForCreateInGroup(targetWorkspaceId, tokenRequestParams);  In the client, I call powerbi.createReport(embedContainer, embedCreateConfiguration); where embedCreateConfiguration includes groupId of target workspace.  In the generated report object, I can see the groupId and datasetId represented in the createConfig attributes.  The standard SaveAs dialog will successfully save the report; however:

    I updated the embedCreateConfiguration settings to include: useCustomSaveAsDialog: true

    I added event handler for the saveAsTriggered event.  I then set targetWorkspaceId as part of the saveAsParameters similar to documentation here.  However, calling the saveAs function does not succeed in saving the report.  That is when I get 403 error similar to above:

    https://wabi-us-north-central-b-redirect.analysis.windows.net/explore/explorations/?name=test

     

    Using the error event handler I captured the error object:

    • detailedMessage: "Unable to save the report"
    • errorCode: undefined
    • level: 2
    • message: "ExplorationContainer_FailedToSaveReportDefaultDetails"

    I would expect this to be effectively the same as the standard SaveAs dialog.  I can't find any information on the ExplorationContainer message.  The example SaveAs code is quite simple, so I'm wondering if this is a bug?

     

    I am using:

    • Microsoft.PowerBI.API (3.28.1)
    • Microsoft.PowerBI.JavaScript (2.18.6)

     

    The service principal has the required API permissions: Workspace.ReadWrite.All, Report.ReadWrite.All, Dataset.ReadWrite.All

    And the fact that the standard dialog saves makes it seem like it is not a permission issue.

     

    Any insight into how I can force the standard SaveAs dialog to use the target workspace or how I can get the custom dialog to work?

    • shietpas_cbts's avatar
      shietpas_cbts
      Frequent Visitor

      I was able to resolve the issue...

       

      I changed my code to use the same ā€œpbiClient.EmbedToken.GenerateTokenā€ API call as view/edit rather than the ā€œpbiClient.Reports.GenerateTokenForCreateInGroupā€ API call.  My understanding was that report creation required the more specific call for creating a report in a group.  However, it appears that it was the cause of the issue, and is still a v1 call.

       

      Using the GenerateToken API instead did resolve the issue.  The custom SaveAs dialog now works and allows me to save to the target workspace.  I simply provide Guid.Empty for the reports portion of the GenerateTokenRequestV2 and include the Dataset and targetWorkspace.

      • gotters's avatar
        gotters
        Resolver I

        Thanks for sharing the fix here. I am still having the same issue as your original issue.

        In the UI code are you specifying the targetWorkspaceId on the SaveAs call (via the SaveAsTriggered event) or is it enough that your token request includes the target workspace?