Forum Discussion

pavanmanideep's avatar
pavanmanideep
Icon for Helper III rankHelper III
1 year ago

Can we deploy Power BI Report to workspace using Azure Pipelines using Service Principal without Pro

Hi,

 

Please suggest if there is any way to deploy Power BI Reports to workspaces in Power BI Service using Service Principalre using Azure Pipeline and without having a Power BI Pro license ? Could you suggest some references?

 

Thank you.

6 Replies

  • Hello pavanmanideep,

     

    To deploy without a Pro license, the target workspace must be backed by Power BI Premium Capacity. The Service Principal should also be assigned the Contributor or Admin role on the workspace.

     

    You can use Invoke-RestMethod in PowerShell (or custom scripts) within your pipeline to interact with the Power BI REST API.

     

    1. Get an authentication token for the Service Principal

    $token = (Invoke-RestMethod -Uri "https://login.microsoftonline.com/{TenantId}/oauth2/v2.0/token" `
        -Method POST `
        -ContentType "application/x-www-form-urlencoded" `
        -Body @{
            grant_type="client_credentials";
            client_id="{Your-Service-Principal-ClientId}";
            client_secret="{Your-Service-Principal-Secret}";
            scope="https://analysis.windows.net/powerbi/api/.default"
        }).access_token
    

    2. Use the Power BI REST API to upload a report

    $workspaceId = "{Workspace-ID}"
    $filePath = "path-to-your-report.pbix"
    $fileContent = [System.IO.File]::ReadAllBytes($filePath)
    
    Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/groups/$workspaceId/imports" `
        -Method POST `
        -Headers @{Authorization = "Bearer $token"} `
        -ContentType "multipart/form-data" `
        -Body @{
            "datasetDisplayName" = "ReportName";
            "file" = $fileContent
        }
    

     Hope this helps.