How to use the PowerBI API to update an Azure Blob Storage datasource?

I’ve got a bunch of storage accounts, all holding similar data but from different environments, and I’m trying to generate a report per storage account in an automated fashion. I’ve got a PBIX file that contains the transformations and visuals that I need.

I’m trying to leverage the PowerBI API via PowerShell to create multiple reports based on that PBIX file (this works) and to then change the data source in the dataset associated with the report to point to the new storage account. However, this is where I’m running into issues. According to the docs it should be fairly straightforward, but I’m getting this vague error:

Parameter UpdateDetails is missing or invalid.

I’ve done some searching and reverse-engineering using the get method and far as I can tell my UpdateDetails payload should be valid.

This is the code I’m running:

    # Path to my pbix file.
    $pbixPath = "C:pathtomydemo.pbix"

    # List of storage accounts with valid sas tokens.
    $storageAccounts = @(
        @{"AccountName"= "account1"; "SasToken"="validSas"},
        @{"AccountName"= "account2"; "SasToken"="validSas"},
        @{"AccountName"= "account3"; "SasToken"="validSas"}
    )

    # Get the workspace
    $workspaceObject = ( Get-PowerBIWorkspace -Name "my workspace" )
    $groupid = $workspaceObject.id

    foreach($storageAccount in $storageAccounts){
        $reportName = $storageAccount.AccountName.Replace("reporting", "")
        Write-Host "Publishing $reportName"

        # Publish the report based on our pbix file.
        $result = New-PowerBIReport -Path $pbixPath -Name $reportName -Workspace $workspaceObject -ConflictAction CreateOrOverwrite

        # Get the dataset associated with the newly published report.
        $dataset = Get-PowerBIDataset -Workspace $workspaceObject | Where-Object {$_.Name -eq $reportName}
        $datasetid = $dataset.id


        # Getting the storage account name currently used by the report's dataset.
        # This account is inherited from the pbix file and needs to be overwritten with $storageAccount.AccountName.
        $DefaultStorageAccount = (Invoke-PowerBIRestMethod -Method GET -Url "datasets/$DataSetId/datasources" | convertfrom-json).value.connectionDetails.account

        # Preparing the body of our request to point to a new storage account
        $body = @"
        {
          "updateDetails": [
            {
              "datasourceSelector": {
                "datasourceType": "AzureBlobs",
                "connectionDetails": {
                  "account": "$DefaultStorageAccount",
                  "domain": "blob.core.windows.net"
                }
              },
              "connectionDetails": {
                "account": "$($storageAccount.AccountName)",
                "domain": "blob.core.windows.net"
              }
            }
          ]
        }
        "@

        # Attempting to point the dataset to a new storage account. This is where the error is thrown.
        Invoke-PowerBIRestMethod -Url "datasets/$DataSetId/Default.UpdateDatasources" -Method Post -Body $body
    }

I tried to update the dataset associated with a PowerBI report to use a new Storage Account. I expected this API call to be accepted without issue, but the vague error doesn’t match the documentation.

New contributor

Tim Groothuis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật