Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi,
I was trying to generate PDF using API call in java code. I tried following API calls but getting empty PDF after exporting as File:
Am I missing anthing here?
Solved! Go to Solution.
Can you try it in Powershell? The below works for me:
# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}
$clientId = "<your client id>"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$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/json'
'Authorization'=$token.CreateAuthorizationHeader()
}
#Report details
$groupsPath = "<workspace guid>"
$reportID = "<report guid>"
# 0. get page names - optional
$uri = “https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/pages"
$Pages = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET
# 1. export request URI
$uri = “https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/ExportTo”
$body = "{ format : `"PDF`” }"
# how to define the pages? powerBIReportConfiguration:{pages:[{pageName:"<page 1 guid>"},{pageName:"page2 guid>"}]}
# issue the export request
$FileExport = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST -body $body
#save the ID - we need it later
$exportId = $FileExport.id
# 2. export request status URI
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/exports/$exportId"
$percentComplete = 0
# repeat rendering status check until status is Succeeded
while ($percentComplete -lt 100) {
Start-Sleep -Seconds 30
$exportStatus = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET
$percentComplete = $exportStatus.percentComplete
Write-Host $percentComplete
}
# 3. retrieve the rendered file
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/exports/$exportId/file"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET -OutFile "test.pdf"
Your while loop needs to check the "percentComplete" export status, not the HTTP 200. Only when percentComplete is 100 can you fetch the file.
There are only two responses mentioned in the API document https://docs.microsoft.com/en-us/rest/api/power-bi/reports/get-export-to-file-status-in-group
You need to look inside the Export response
Verified with PercentComplate attribute of Export and even after that getting same issue.
Did you wait for PercentComplete to reach 100?
Yes, I waited till 100 percentage then called next API call
Can you try it in Powershell? The below works for me:
# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
if(-not (Get-Module AzureRm.Profile)) {
Import-Module AzureRm.Profile
}
$clientId = "<your client id>"
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$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/json'
'Authorization'=$token.CreateAuthorizationHeader()
}
#Report details
$groupsPath = "<workspace guid>"
$reportID = "<report guid>"
# 0. get page names - optional
$uri = “https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/pages"
$Pages = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET
# 1. export request URI
$uri = “https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/ExportTo”
$body = "{ format : `"PDF`” }"
# how to define the pages? powerBIReportConfiguration:{pages:[{pageName:"<page 1 guid>"},{pageName:"page2 guid>"}]}
# issue the export request
$FileExport = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST -body $body
#save the ID - we need it later
$exportId = $FileExport.id
# 2. export request status URI
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/exports/$exportId"
$percentComplete = 0
# repeat rendering status check until status is Succeeded
while ($percentComplete -lt 100) {
Start-Sleep -Seconds 30
$exportStatus = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET
$percentComplete = $exportStatus.percentComplete
Write-Host $percentComplete
}
# 3. retrieve the rendered file
$uri = "https://api.powerbi.com/v1.0/myorg/groups/$groupsPath/reports/$reportID/exports/$exportId/file"
Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET -OutFile "test.pdf"
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 10 | |
| 10 | |
| 4 | |
| 3 | |
| 3 |