Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
amaaiia
Skilled Sharer
Skilled Sharer

How to export a PBI report with api

Hi.

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 https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file-in-group the documentation: 

 

1. I set variables:

 

workspaceId="XXXXXXX"
reportId="YYYYYYYYY"
tenant_id="ZZZZZZZZZZZ"
client_id="WWWWWWWWWWWW"
client_secret="CCCCCC"

 

 

2. I get the token:

 

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")

 

3. I call ExportTo API call:

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))

And I get this output:

{'@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'}

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:

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)

With output message: "No HTTP resource was found that matches the request URI..."

 

Why is it not working?

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Try the same in the API sandbox. Should work.  Remove the "/status"  part of the URL.

 

Reports - Get Export To File Status In Group - REST API (Power BI Power BI REST APIs) | Microsoft Le...

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Try the same in the API sandbox. Should work.  Remove the "/status"  part of the URL.

 

Reports - Get Export To File Status In Group - REST API (Power BI Power BI REST APIs) | Microsoft Le...

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.