<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Not able to generate PDF via PowerBI API call in java in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2078792#M31787</link>
    <description>&lt;P&gt;Your while loop needs to check the "percentComplete"&amp;nbsp; export status, not the HTTP 200.&amp;nbsp; Only when percentComplete is 100 can you fetch the file.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Sep 2021 01:04:04 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2021-09-16T01:04:04Z</dc:date>
    <item>
      <title>Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2077768#M31769</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;POST &lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/ExportTo" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/ExportTo&lt;/A&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;From this api call, I get the export id.&lt;/LI&gt;&lt;LI&gt;To get the status of the exported file, used below API call:&lt;BR /&gt;GET &lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/exports/{exportId}" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/exports/{exportId}&lt;/A&gt;&lt;BR /&gt;Added while loop to wait until the status is 200 OK&lt;/LI&gt;&lt;LI&gt;Once status is 200, I have called below API call:&lt;BR /&gt;GET &lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/exports/{exportId}/file" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/exports/{exportId}/file&lt;/A&gt;&lt;BR /&gt;This api provides the File. Following code snipet I have used:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;RestTemplate getReportRestTemplate = new RestTemplate();&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;HttpHeaders headers = new HttpHeaders();&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;headers.put("Content-Type", Arrays.asList("application/pdf"));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;headers.put("Accept", Arrays.asList("application/*"));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;headers.put("Authorization", Arrays.asList("Bearer " + accessToken));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;// HTTP entity object - holds header and body&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;HttpEntity&amp;lt;String&amp;gt; reqEntity = new HttpEntity&amp;lt;&amp;gt; (headers);&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ResponseEntity&amp;lt;String&amp;gt; response = getReportRestTemplate.exchange(urlStringBuilder.toString(), HttpMethod.GET, reqEntity, String.class);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Path file = Paths.get("D:\\test.pdf");&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;try (InputStream in = new ByteArrayInputStream(response.getBody().getBytes())) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Files.copy(in, file);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Am I missing anthing here?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Sep 2021 12:53:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2077768#M31769</guid>
      <dc:creator>sharvan270</dc:creator>
      <dc:date>2021-09-15T12:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2078792#M31787</link>
      <description>&lt;P&gt;Your while loop needs to check the "percentComplete"&amp;nbsp; export status, not the HTTP 200.&amp;nbsp; Only when percentComplete is 100 can you fetch the file.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 01:04:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2078792#M31787</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-09-16T01:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2079092#M31794</link>
      <description>&lt;P&gt;There are only two responses mentioned in the API document&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/reports/get-export-to-file-status-in-group" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/reports/get-export-to-file-status-in-group&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sharvan270_0-1631767175411.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/594474iFE6A45415D036591/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sharvan270_0-1631767175411.png" alt="sharvan270_0-1631767175411.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 04:40:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2079092#M31794</guid>
      <dc:creator>sharvan270</dc:creator>
      <dc:date>2021-09-16T04:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2080268#M31806</link>
      <description>&lt;P&gt;You need to look inside the Export response&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 11:57:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2080268#M31806</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-09-16T11:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2081855#M31835</link>
      <description>&lt;P&gt;Verified with PercentComplate attribute of Export and even after that getting same issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 06:32:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2081855#M31835</guid>
      <dc:creator>sharvan270</dc:creator>
      <dc:date>2021-09-17T06:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082551#M31848</link>
      <description>&lt;P&gt;Did you wait for PercentComplete to reach 100?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 11:26:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082551#M31848</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-09-17T11:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082849#M31851</link>
      <description>&lt;P&gt;Yes, I waited till 100 percentage then called next API call&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 14:06:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082849#M31851</guid>
      <dc:creator>sharvan270</dc:creator>
      <dc:date>2021-09-17T14:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to generate PDF via PowerBI API call in java</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082943#M31854</link>
      <description>&lt;P&gt;Can you try it in Powershell?&amp;nbsp; The below works for me:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
    if(-not (Get-Module AzureRm.Profile)) {
        Import-Module AzureRm.Profile
    }
    $clientId = "&amp;lt;your client id&amp;gt;"
    $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 = "&amp;lt;workspace guid&amp;gt;"
$reportID   = "&amp;lt;report guid&amp;gt;"
# 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:"&amp;lt;page 1 guid&amp;gt;"},{pageName:"page2 guid&amp;gt;"}]}
# 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"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 14:39:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Not-able-to-generate-PDF-via-PowerBI-API-call-in-java/m-p/2082943#M31854</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-09-17T14:39:17Z</dc:date>
    </item>
  </channel>
</rss>

