<?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 How to export a PBI report with api in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-export-a-PBI-report-with-api/m-p/4570839#M7501</link>
    <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I have a report in my Fabric workspace, and I'm trying to export is as PDF with a notebook in Fabric, but I can't get the status of the API call. I'm following&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file-in-group" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file-in-group&lt;/A&gt; the documentation:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. I set variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;workspaceId="XXXXXXX"
reportId="YYYYYYYYY"
tenant_id="ZZZZZZZZZZZ"
client_id="WWWWWWWWWWWW"
client_secret="CCCCCC"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I get the token:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests

url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}
data = {
    "grant_type": "client_credentials",
    "client_id": client_id,
    "client_secret": client_secret,
    "scope": "https://analysis.windows.net/powerbi/api/.default"
}

response = requests.post(url, headers=headers, data=data)
access_token = response.json().get("access_token")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. I call ExportTo API call:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import json
url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspaceId}/reports/{reportId}/ExportTo"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + access_token
}
payload = {
    "format": "PDF",
}

response = requests.post(url, headers=headers, data=json.dumps(payload))&lt;/LI-CODE&gt;
&lt;P&gt;And I get this output:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{'@odata.context': 'https://api.powerbi.com/v1.0/myorg/groups/xxxxxxxxxx/$metadata#exports/$entity', 'id': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'createdDateTime': '2025-02-25T11:59:20.2275354Z', 'lastActionDateTime': '2025-02-25T11:59:20.2275354Z', 'reportId': 'xxxxxxxxxxxxxxxxxxxxxxxxx', 'status': 'NotStarted', 'percentComplete': 0, 'expirationTime': '0001-01-01T00:00:00Z'}&lt;/LI-CODE&gt;
&lt;P&gt;Following the documentation, I need to wait until status is completed. However, If I try to check the status of the exported ID, i have a HTTP resource not found:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;exportId = response.json().get("id")
url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspaceId}/reports/{reportId}/exports/{exportId}/status"
headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
}

response = requests.get(url, headers=headers)
status = response.json()
print(status)&lt;/LI-CODE&gt;
&lt;P&gt;With output message:&amp;nbsp;&lt;SPAN&gt;"No HTTP resource was found that matches the request URI..."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why is it not working?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2025 12:10:22 GMT</pubDate>
    <dc:creator>amaaiia</dc:creator>
    <dc:date>2025-02-25T12:10:22Z</dc:date>
    <item>
      <title>How to export a PBI report with api</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-export-a-PBI-report-with-api/m-p/4570839#M7501</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;I have a report in my Fabric workspace, and I'm trying to export is as PDF with a notebook in Fabric, but I can't get the status of the API call. I'm following&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file-in-group" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file-in-group&lt;/A&gt; the documentation:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. I set variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;workspaceId="XXXXXXX"
reportId="YYYYYYYYY"
tenant_id="ZZZZZZZZZZZ"
client_id="WWWWWWWWWWWW"
client_secret="CCCCCC"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I get the token:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests

url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}
data = {
    "grant_type": "client_credentials",
    "client_id": client_id,
    "client_secret": client_secret,
    "scope": "https://analysis.windows.net/powerbi/api/.default"
}

response = requests.post(url, headers=headers, data=data)
access_token = response.json().get("access_token")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. I call ExportTo API call:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import json
url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspaceId}/reports/{reportId}/ExportTo"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + access_token
}
payload = {
    "format": "PDF",
}

response = requests.post(url, headers=headers, data=json.dumps(payload))&lt;/LI-CODE&gt;
&lt;P&gt;And I get this output:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{'@odata.context': 'https://api.powerbi.com/v1.0/myorg/groups/xxxxxxxxxx/$metadata#exports/$entity', 'id': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'createdDateTime': '2025-02-25T11:59:20.2275354Z', 'lastActionDateTime': '2025-02-25T11:59:20.2275354Z', 'reportId': 'xxxxxxxxxxxxxxxxxxxxxxxxx', 'status': 'NotStarted', 'percentComplete': 0, 'expirationTime': '0001-01-01T00:00:00Z'}&lt;/LI-CODE&gt;
&lt;P&gt;Following the documentation, I need to wait until status is completed. However, If I try to check the status of the exported ID, i have a HTTP resource not found:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;exportId = response.json().get("id")
url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspaceId}/reports/{reportId}/exports/{exportId}/status"
headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
}

response = requests.get(url, headers=headers)
status = response.json()
print(status)&lt;/LI-CODE&gt;
&lt;P&gt;With output message:&amp;nbsp;&lt;SPAN&gt;"No HTTP resource was found that matches the request URI..."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why is it not working?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 12:10:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-export-a-PBI-report-with-api/m-p/4570839#M7501</guid>
      <dc:creator>amaaiia</dc:creator>
      <dc:date>2025-02-25T12:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to export a PBI report with api</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-export-a-PBI-report-with-api/m-p/4572661#M7504</link>
      <description>&lt;P&gt;Try the same in the API sandbox. Should work.&amp;nbsp; Remove the "/status"&amp;nbsp; part of the URL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/reports/get-export-to-file-status-in-group" target="_blank"&gt;Reports - Get Export To File Status In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 13:30:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-to-export-a-PBI-report-with-api/m-p/4572661#M7504</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2025-02-25T13:30:39Z</dc:date>
    </item>
  </channel>
</rss>

