Forum Discussion
powerbi_jenhen
4 years agoResolver II
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 worksp...
- 4 years ago
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 - 3 years ago
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}
Kunal2699
8 months agoNew Member