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:\path\to\my\demo.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.
Try adding:
-ContentType "application/json"
as an additional parameter.
Failing that, it could be that "AzureBlobs" isn't supported by this API call. From the documentation:
Limitations
Only these data sources are supported: SQL Server, Azure SQL Server, Azure Analysis Services, Azure Synapse, OData, SharePoint, Teradata, and SAP HANA. For other data sources, use the Update Parameters In Group API call.