0

I'm trying to upload PowerBI .pbix report stored on my local PC to PowerBI Service using Rest API. I haven't had problems exporting reports to my computer before, only agonizing over importing them to the server.

Here is the documentation: https://learn.microsoft.com/en-us/rest/api/power-bi/imports/post-import-in-group

And mycode:

Connect-PowerBIServiceAccount
$file = "C:\Sales.pbix"
$Payload =@"
{ "ImportInfo" : { "filePath" : "$file" , "connectionType" : "import" }}
"@
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/<here I put workspace ID>/imports?datasetDisplayName=Test" -Method Post -Body $Payload -ContentType 'application/json'

And error:

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:21 char:1
+ Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/gro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
Rafał
  • 51
  • 10

1 Answers1

0

The error does not provide any meaningful information what happened. You can use a tool like Fiddler to see what exactly Power BI gives you as a response. However, I wonder why you are trying to upload the report using a raw API call, while you can use the New-PowerBIReport cmdlet. Just do something like this:

Import-Module MicrosoftPowerBIMgmt

Connect-PowerBIServiceAccount

$workspaceName = "Target workspace or whatever..."

$workspace = Get-PowerBIWorkspace -Name $workspaceName

if($workspace)
{
  Write-Host "The workspace named $workspaceName already exists."
}
else
{
  Write-Host "Creating new workspace named $workspaceName..."
  $workspace = New-PowerBIWorkspace -Name $workspaceName
}

$file = "C:\Sales.pbix"

New-PowerBIReport -Path $file -Workspace $workspace -ConflictAction CreateOrOverwrite

Disconnect-PowerBIServiceAccount
Andrey Nikolov
  • 12,967
  • 3
  • 20
  • 32