Deploy a Power BI project using Fabric APIs
This article explains how to deploy a Power BI project (.pbip) using Fabric REST APIs and a PowerShell script. This article is written for developers who need complete control over their Power BI deployment process and should serve as an example. The example's pattern can be applied to other languages or tools capable of calling the Fabric REST APIs.
Save your work as a Power BI project
To use the Fabric REST APIs, you need to save your work as a Power BI project file (.pbip).
Understand which APIs are used
To deploy the .pbip content, use the following Fabric REST APIs:
List Items - Lists the existing items in the workspace.
Create Item - Creates a new item.
Update Item Definition - Updates the item definition. This API is used in case the item already exists.
PowerShell script
To deploy your project, use a PowerShell script. The script executes the following actions:
Ensures the workspace exists.
Creates or updates the Power BI report and semantic model in the workspace, using the Power BI Project file definitions.
The script uses the FabricPS-PBIP module, which serves as a wrapper for the Fabric APIs and handles tasks such as authentication, asynchronous calls, and metadata management for Power BI project files.
Note
The powershell module fabricps-pbip is open-source and Microsoft does not offer support or documentation for it.
Script template
Use this script template to deploy your Power BI project:
# Parameters
$workspaceName = "[Workspace Name]"
$pbipSemanticModelPath = "[PBIP Path]\[Item Name].SemanticModel"
$pbipReportPath = "[PBIP Path]\[Item Name].Report"
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
Set-Location $currentPath
# Download modules and install
New-Item -ItemType Directory -Path ".\modules" -ErrorAction SilentlyContinue | Out-Null
@("https://raw.githubusercontent.com/microsoft/Analysis-Services/master/pbidevmode/fabricps-pbip/FabricPS-PBIP.psm1"
, "https://raw.githubusercontent.com/microsoft/Analysis-Services/master/pbidevmode/fabricps-pbip/FabricPS-PBIP.psd1") |% {
Invoke-WebRequest -Uri $_ -OutFile ".\modules\$(Split-Path $_ -Leaf)"
}
if(-not (Get-Module Az.Accounts -ListAvailable)) {
Install-Module Az.Accounts -Scope CurrentUser -Force
}
Import-Module ".\modules\FabricPS-PBIP" -Force
# Authenticate
Set-FabricAuthToken -reset
# Ensure workspace exists
$workspaceId = New-FabricWorkspace -name $workspaceName -skipErrorIfExists
# Import the semantic model and save the item id
$semanticModelImport = Import-FabricItem -workspaceId $workspaceId -path $pbipSemanticModelPath
# Import the report and ensure its binded to the previous imported report
$reportImport = Import-FabricItem -workspaceId $workspaceId -path $pbipReportPath -itemProperties @{"semanticModelId" = $semanticModelImport.Id}