Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
powerbi_jenhen
Resolver II
Resolver 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 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.

2 ACCEPTED SOLUTIONS
powerbi_jenhen
Resolver II
Resolver 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 = $stageOrder
                datasets = @(
                    @{sourceId = $datasetArtifact.artifactId }
                )
                reports = @(
                    @{sourceId = $reportArtifact.artifactId }
                )        
                options = @{
                    allowCreateArtifact = $TRUE
                    allowOverwriteArtifact = $TRUE
                }  
                updateAppSettings = @{
                    updateAppInTargetWorkspace = $TRUE
                }
            } | ConvertTo-Json

View solution in original post

powerbi_jenhen
Resolver II
Resolver 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: "$pipelineName
        Write-Host "Pipeline: "$pipeline

        if(!$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: "$workspaceId
        Write-Host "App Workspace ID: "$app

        if(!$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.artifactId
 
if($app)
        {
            $body =
            @{
                sourceStageOrder = $stageOrder
                   
                datasets = @(
                @{sourceId = $datasetArtifactId }
                )
                   
                reports = @(
                    @{sourceId = $reportArtifactId }
                )        

                options = @{
                    # Allows creating new artifact if needed on the Test stage workspace
                    allowCreateArtifact = $TRUE

                    # Allows overwriting existing artifact if needed on the Test stage workspace
                    allowOverwriteArtifact = $TRUE
                }    
                updateAppSettings = @{
                    updateAppInTargetWorkspace = $TRUE
                }          
            } | ConvertTo-Json
        }
        else
        {
            $body =
            @{
                sourceStageOrder = $stageOrder
                   
                datasets = @(
                @{sourceId = $datasetArtifactId }
                )
                   
                reports = @(
                    @{sourceId = $reportArtifactId }
                )        

                options = @{
                    # Allows creating new artifact if needed on the Test stage workspace
                    allowCreateArtifact = $TRUE

                    # Allows overwriting existing artifact if needed on the Test stage workspace
                    allowOverwriteArtifact = $TRUE
                }          
            } | ConvertTo-Json
        }

View solution in original post

6 REPLIES 6
pvuppala
Advocate II
Advocate II

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?

powerbi_jenhen
Resolver II
Resolver 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: "$pipelineName
        Write-Host "Pipeline: "$pipeline

        if(!$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: "$workspaceId
        Write-Host "App Workspace ID: "$app

        if(!$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.artifactId
 
if($app)
        {
            $body =
            @{
                sourceStageOrder = $stageOrder
                   
                datasets = @(
                @{sourceId = $datasetArtifactId }
                )
                   
                reports = @(
                    @{sourceId = $reportArtifactId }
                )        

                options = @{
                    # Allows creating new artifact if needed on the Test stage workspace
                    allowCreateArtifact = $TRUE

                    # Allows overwriting existing artifact if needed on the Test stage workspace
                    allowOverwriteArtifact = $TRUE
                }    
                updateAppSettings = @{
                    updateAppInTargetWorkspace = $TRUE
                }          
            } | ConvertTo-Json
        }
        else
        {
            $body =
            @{
                sourceStageOrder = $stageOrder
                   
                datasets = @(
                @{sourceId = $datasetArtifactId }
                )
                   
                reports = @(
                    @{sourceId = $reportArtifactId }
                )        

                options = @{
                    # Allows creating new artifact if needed on the Test stage workspace
                    allowCreateArtifact = $TRUE

                    # Allows overwriting existing artifact if needed on the Test stage workspace
                    allowOverwriteArtifact = $TRUE
                }          
            } | ConvertTo-Json
        }
powerbi_jenhen
Resolver II
Resolver 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 = $stageOrder
                datasets = @(
                    @{sourceId = $datasetArtifact.artifactId }
                )
                reports = @(
                    @{sourceId = $reportArtifact.artifactId }
                )        
                options = @{
                    allowCreateArtifact = $TRUE
                    allowOverwriteArtifact = $TRUE
                }  
                updateAppSettings = @{
                    updateAppInTargetWorkspace = $TRUE
                }
            } | ConvertTo-Json

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.

What API endpoint did you do this with?

$url = "pipelines/{0}/Deploy" -f $pipeline.Id
 
$body = @{
            sourceStageOrder = $stageOrder
               
            reports = @(
                @{sourceId = $rdlArtifactId }
            )        

            options = @{
                # Allows creating new artifact if needed on the Test stage workspace
                allowCreateArtifact = $TRUE

                # Allows overwriting existing artifact if needed on the Test stage workspace
                allowOverwriteArtifact = $TRUE
            }

            updateAppSettings = @{
                    updateAppInTargetWorkspace = $TRUE
                }
               
        } | ConvertTo-Json
 
$deployResult = Invoke-PowerBIRestMethod -Url $url -Method Post -Body $body | ConvertFrom-Json

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors