Forum Discussion
Overwrite report when copy/clone via powershell or API?
Has anybody solved this?
I want the PBI Service to overwrite/update my report and not give me back a new Report Id everytime I deploy to a workspace(/environment).
I can use the "Import" REST API and/or the MicrosoftPowerBIMgmt New-PowerBIReport cmdlet to post an updated report, but both will give me a new Report Id for the report which will break all links and references to the original report of the same name.
Hi mbutler71,
If you need more, let me know. I am running into a meeting this morning and kept this "short."
We have code that will find the report id "by name" dynamically, if you need it.
1. Copy pbix files from Drive to "Staging Area" workspace.
New-PowerBIReport -Path $fileToPublish -WorkspaceId $stagingGroupId -ConflictAction CreateOrOverwrite -Verbose
Copying from the drive to Staging will keep the Same ID in place IF the dataset in Staging is the same as the dataset you use for development.
- We use a Golden Dataset that works for all workspaces.
- Publish the Golden Dataset to Staging
- Build reports that connect to the Staging Dataset in the Service
- Publish those reports to Staging with the above command.
2. Update Target report CONTENT from a report in Staging to the Target workspace
#Use UpdateReportContent API to copy content from Staging to Target workspace
# Update "Update Report Content In Group" URL - POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/UpdateReportContent
# Update "Update Report Content In Group" URL - POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/UpdateReportContent
$updateReportUrl = "groups/$GroupId/reports/$reportIdToUpdate/UpdateReportContent"
#Write-Output "$updateReportUrl"
# The Dataset parameters to update
$postParams = @{
sourceReport =
@{
sourceReportId="$($reportIdFromStaging)"
sourceWorkspaceId="$($stagingGroupId)"
}
sourceType = "ExistingReport"
} | ConvertTo-Json
Write-Output "$postParams"
Invoke-PowerBIRestMethod -Url $updateReportUrl -Method Post -Body $postParams -ContentType $content -Verbose
NOTES
The "UpdateReportContent" API will replace the report content and rebind to the target's data source AND keep the report ID in tact.
- mbutler714 years agoAdvocate I
Awesome, thanks so much for posting. This is working great!
I'm not losing the report id now for our links.function Update-ReportContent{ # 08.27.2021 param ($stagingReportId, $stagingWorkspaceId, $targetReportId, $targetWorkspaceId, $RestAPIURL) $updateReportUrl = $RestAPIURL+"groups/$targetWorkspaceId/reports/$targetReportId/UpdateReportContent"; $postParams = @{ sourceReport = @{ sourceReportId="$($stagingReportId)" sourceWorkspaceId="$($stagingWorkspaceId)" } sourceType = "ExistingReport" } | ConvertTo-Json $content = "application/json"; Invoke-PowerBIRestMethod -Url $updateReportUrl -Method Post -Body $postParams -ContentType $content -Verbose; #Remove the Staging file Remove-PowerBIReport -Id $stagingReportId -WorkspaceId $stagingWorkspaceId; }