Forum Discussion
Power BI Rest API to Update Workspace App
Hi,
I'm using the Power BI Rest API via Powershell within ADO pipelines to fully automate the deployment of artifacts (datasets, reports, dashboards) across DEV->ACC->PROD Power BI Service workspaces. I use Power BI Service deployment pipelines but automate this very manual deployment process via "Selective Deploy" API calls within the ADO pipelines along with governance processes like archiving the artifacts incase of rollback etc. The one thing missing to fully automate the end to end process is to update the workspace apps once the artifacts have been deployed, I can't seem to find this API call, can this be done within the POST body of the Invoke-PowerBIRestMethod?
Thanks.
Figured this out, simply add the below to the body. The app will initially need to be published for this to work:
updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}Typical full body:$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifact.artifactId })reports = @(@{sourceId = $reportArtifact.artifactId })options = @{allowCreateArtifact = $TRUEallowOverwriteArtifact = $TRUE}updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}} | ConvertTo-JsonCheck the pipeline and app exist by passing these artifact values into the function:
# Get pipelines$pipelines = (Invoke-PowerBIRestMethod -Url "pipelines" -Method Get | ConvertFrom-Json).value# Try to find the pipeline by display name$pipeline = $pipelines | Where-Object {$_.DisplayName -eq $pipelineName}Write-Host "Pipeline Name: "$pipelineNameWrite-Host "Pipeline: "$pipelineif(!$pipeline){Write-Host "A pipeline with the requested name was not found"return}# Get apps$apps = (Invoke-PowerBIRestMethod -Url "admin/apps?%24top=500" -Method Get | ConvertFrom-Json).value#Write-Host "Apps: "$apps# Try to find the apps by workspace id$app = $apps | Where-Object {$_.workspaceId -eq $workspaceId}Write-Host "Workspace ID: "$workspaceIdWrite-Host "App Workspace ID: "$appif(!$app){Write-Host "A app with the requested workspace id was not found"#return}Set the different deployment bodies:# Get pipeline stage artifacts$artifactsUrl = "pipelines/{0}/stages/{1}/artifacts" -f $pipeline.Id,$stageOrder$artifacts = Invoke-PowerBIRestMethod -Url $artifactsUrl -Method Get | ConvertFrom-Json$ReportDisplayName = [io.path]::GetFileNameWithoutExtension($fileName)$reportArtifact = $artifacts.reports | Where-Object {$_.artifactDisplayName -eq $ReportDisplayName}$datasetArtifact = $artifacts.datasets | Where-Object {$_.artifactDisplayName -eq $ReportDisplayName}$reportArtifactId = $reportArtifact.artifactId$datasetArtifactId = $datasetArtifact.artifactIdif($app){$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifactId })reports = @(@{sourceId = $reportArtifactId })options = @{# Allows creating new artifact if needed on the Test stage workspaceallowCreateArtifact = $TRUE# Allows overwriting existing artifact if needed on the Test stage workspaceallowOverwriteArtifact = $TRUE}updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}} | ConvertTo-Json}else{$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifactId })reports = @(@{sourceId = $reportArtifactId })options = @{# Allows creating new artifact if needed on the Test stage workspaceallowCreateArtifact = $TRUE# Allows overwriting existing artifact if needed on the Test stage workspaceallowOverwriteArtifact = $TRUE}} | ConvertTo-Json}
8 Replies
- powerbi_jenhenResolver II
Figured this out, simply add the below to the body. The app will initially need to be published for this to work:
updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}Typical full body:$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifact.artifactId })reports = @(@{sourceId = $reportArtifact.artifactId })options = @{allowCreateArtifact = $TRUEallowOverwriteArtifact = $TRUE}updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}} | ConvertTo-Json- AnonymousNot applicable
I have a similar problem: I want to update a workspace app via Powershell. But I do not use Pipelines. What would the skript look like? Thanks a lot in advance.
- AnonymousNot applicable
Did you figure out if the power bi or fabric api support this?
- kerskiAdvocate II
What API endpoint did you do this with?
- powerbi_jenhenResolver II$url = "pipelines/{0}/Deploy" -f $pipeline.Id$body = @{sourceStageOrder = $stageOrderreports = @(@{sourceId = $rdlArtifactId })options = @{# Allows creating new artifact if needed on the Test stage workspaceallowCreateArtifact = $TRUE# Allows overwriting existing artifact if needed on the Test stage workspaceallowOverwriteArtifact = $TRUE}updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}} | ConvertTo-Json$deployResult = Invoke-PowerBIRestMethod -Url $url -Method Post -Body $body | ConvertFrom-Json
- powerbi_jenhenResolver II
Check the pipeline and app exist by passing these artifact values into the function:
# Get pipelines$pipelines = (Invoke-PowerBIRestMethod -Url "pipelines" -Method Get | ConvertFrom-Json).value# Try to find the pipeline by display name$pipeline = $pipelines | Where-Object {$_.DisplayName -eq $pipelineName}Write-Host "Pipeline Name: "$pipelineNameWrite-Host "Pipeline: "$pipelineif(!$pipeline){Write-Host "A pipeline with the requested name was not found"return}# Get apps$apps = (Invoke-PowerBIRestMethod -Url "admin/apps?%24top=500" -Method Get | ConvertFrom-Json).value#Write-Host "Apps: "$apps# Try to find the apps by workspace id$app = $apps | Where-Object {$_.workspaceId -eq $workspaceId}Write-Host "Workspace ID: "$workspaceIdWrite-Host "App Workspace ID: "$appif(!$app){Write-Host "A app with the requested workspace id was not found"#return}Set the different deployment bodies:# Get pipeline stage artifacts$artifactsUrl = "pipelines/{0}/stages/{1}/artifacts" -f $pipeline.Id,$stageOrder$artifacts = Invoke-PowerBIRestMethod -Url $artifactsUrl -Method Get | ConvertFrom-Json$ReportDisplayName = [io.path]::GetFileNameWithoutExtension($fileName)$reportArtifact = $artifacts.reports | Where-Object {$_.artifactDisplayName -eq $ReportDisplayName}$datasetArtifact = $artifacts.datasets | Where-Object {$_.artifactDisplayName -eq $ReportDisplayName}$reportArtifactId = $reportArtifact.artifactId$datasetArtifactId = $datasetArtifact.artifactIdif($app){$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifactId })reports = @(@{sourceId = $reportArtifactId })options = @{# Allows creating new artifact if needed on the Test stage workspaceallowCreateArtifact = $TRUE# Allows overwriting existing artifact if needed on the Test stage workspaceallowOverwriteArtifact = $TRUE}updateAppSettings = @{updateAppInTargetWorkspace = $TRUE}} | ConvertTo-Json}else{$body =@{sourceStageOrder = $stageOrderdatasets = @(@{sourceId = $datasetArtifactId })reports = @(@{sourceId = $reportArtifactId })options = @{# Allows creating new artifact if needed on the Test stage workspaceallowCreateArtifact = $TRUE# Allows overwriting existing artifact if needed on the Test stage workspaceallowOverwriteArtifact = $TRUE}} | ConvertTo-Json} - Kunal2699New Member
- pvuppalaHelper V
Has anyone tried to get this API working to Update or Publish the app ? I'm curious if it only works for Premium since it uses Deployment pipelines?