Forum Discussion
Create Report in Embedded Power BI with GenerateTokenRequestV2
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:
- It saves to the Dataset's workspace rather than the specified target workspace / groupId (set on the embedToken and in the embedCreateConfiguration) - this is the real issue for my purpose
- It still generates 401 error, but able to proceed: https://wabi-us-north-central-b-redirect.analysis.windows.net/metadata/customVisualsStore/organization/visuals 401
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?
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.