Hello,
First of all, I am sorry if I posted this in a wrong topic section, but I could not find any better to fit the Power BI REST API. I have a problem with the "Export Report In Group" functionality. I am using PowerShell to execute the call and save the file. My code works, I do not get any errors. I get a valid response and the files are saved. Problem is, that I cannot open the file with Power BI Desktop, failing with the following error:
I save the files in "pbix" format. I tried saving them as "zip" and no format whatsoever but none of the combination works as expected. The reports were created and published using Power BI May 2018 and I tried to open them with the same version and Power BI June 2018. Can anyone help me with this problem?
My PowerShell code looks as following (I dotted out the Ids):
# declare parameters $sourceReportGroupId = "..." $destinationFolder = "C:\Users\pawel.kucharski\Documents\MTV\Azure\Downloaded" $clientId = "..." # End Parameters ======================================= # Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD function GetAuthToken { $adal = "${envrogramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.3.3\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" $adalforms = "${env
rogramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.3.3\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null $redirectUri = "https://oauth.powerBI.com/PBIMTVAdmin" $resourceAppIdURI = "https://analysis.windows.net/powerbi/api" $authority = "https://login.microsoftonline.com/common/oauth2/authorize"; $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto") return $authResult } # Get the auth token from AAD $token = GetAuthToken # Building Rest API header with authorization token $authHeader = @{ #'Content-Type'='application/zip' 'Authorization'=$token.CreateAuthorizationHeader() } # properly format groups path $sourceGroupsPath = "" if ($sourceReportGroupId -eq "me") { $sourceGroupsPath = "myorg" } else { $sourceGroupsPath = "myorg/groups/$sourceReportGroupId" } # Get reports $uri = "https://api.powerbi.com/v1.0/$sourceGroupsPath/reports" $reports = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET -Verbose #$reports | ConvertTo-Json | Out-File "C:\Users\kuchapaw\Documents\PowerBI\responseJson.json" #$reports.value | Out-File "C:\Users\kuchapaw\Documents\PowerBI\response.json" #export each report from the group foreach($report in $reports.value) { $reportId = $report.id $reportName = $report.name $filePath = "$destinationFolder/$reportName.pbix" $uri2 = "https://api.powerbi.com/v1.0/$sourceGroupsPath/reports/$reportId/Export" $reportResponse = Invoke-RestMethod -Uri $uri2 -Headers $authHeader -Method GET -Verbose $reportResponse | Out-File $filePath }
Thank you!