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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
BhumitraSharma
Frequent Visitor

PowerBI Export RestAPI failing for 500MB file

Hi Everyone, I am stuck with a very weird problem. I have to download a .PBIX file that is uploaded on our embed instance workspace. To download the same I am using the /Export api as mentioned in the below documentation:
https://learn.microsoft.com/en-us/rest/api/power-bi/reports/export-report-in-group

Now for small reports this works fine but for reports around 500Mb+ this takes an exact 4 minutes and fails. I tried the same thing several times and sometimes it downloaded the file in under 2 minutes and otherwise touched 4 minute mark and failed with an internal server error (500) no other details.

As recomended in the documentation I added preferClientRouting as a query param with value equal to true. Mostly it returned 307 and sometimes even directly downloaded the file, I assume it was hitting the correct cluster bymistake. If I followed the redirect URL it again ran till 4 minutes and failed.

My question is how can I download a PBIX file of a big size from the server without running into this 4 minute error. Note I am using a python code which directly makes an API call. Let me know if you need some code snippets or anything extra to answer this question. Thankyou very much.

5 REPLIES 5
Ahmed-Elfeel
Solution Sage
Solution Sage

Hi @BhumitraSharma,

I hope you are doing well today☺️❤️

 

This issue known as 4 minute timeout limitation, It is a hard limit on the service side and for large files (especially 500MB+) the export process often exceeds this limit. So Here is Some Approaches:

 

First Approach: Use Async Pattern with Export to File (its specifically designed for large exports)

  • The Export API has a synchronous limit Instead of this use the asynchronous Export to File API which is designed for large reports:
# Step 1: Start export job
start_response = requests.post(
    f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/ExportTo",
    headers={"Authorization": f"Bearer {access_token}"},
    json={
        "format": "PBIX",
        "powerBIReportConfiguration": {
            "includeReportMetadata": True
        }
    }
)

# Get the export job ID
export_id = start_response.json()["id"]

# Step 2: Poll for status
while True:
    status_response = requests.get(
        f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/exports/{export_id}",
        headers={"Authorization": f"Bearer {access_token}"}
    )
    
    status = status_response.json()["status"]
    
    if status == "Succeeded":
        # Step 3: Download the file
        result_url = status_response.json()["resourceLocation"]
        download_response = requests.get(result_url)
        with open("report.pbix", "wb") as f:
            f.write(download_response.content)
        break
    elif status in ["Failed", "TimedOut"]:
        raise Exception(f"Export failed: {status_response.json()}")
    else:
        time.sleep(5)  # Wait before polling again

 

Second Approach: Increase Timeout and Handle Retries

If you must use the synchronous Export API you can just increase the timeout:

import requests
import time
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type

@retry(
    stop=stop_after_attempt(3),
    wait=wait_exponential(multiplier=1, min=4, max=10),
    retry=retry_if_exception_type(requests.exceptions.Timeout)
)
def export_large_report(workspace_id, report_id, access_token):
    url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/Export"
    
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Accept": "application/octet-stream"
    }
    
    params = {
        "format": "PBIX",
        "preferClientRouting": "true"
    }
    
    # Use streaming to handle large files
    with requests.get(url, headers=headers, params=params, stream=True, timeout=300) as response:
        response.raise_for_status()
        
        with open("report.pbix", "wb") as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
    
    return True

 

Bonus Solution: PowerShell 

If Python continues to have issues, use PowerShell which handles large file transfers better:

$headers = @{
    "Authorization" = "Bearer $accessToken"
    "Accept" = "application/octet-stream"
}

$params = @{
    "format" = "PBIX"
    "preferClientRouting" = "true"
}

Invoke-RestMethod -Uri $url -Headers $headers -Method Get -Body $params `
    -OutFile "report.pbix" -TimeoutSec 600

 

if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.

Hi Ahmed,

 

Thanks a lot for your feedback and recomendations. I have the below observations after running these codes:
1. When hitting the ExportTo restAPI, power bi server returned back with a failure that PBIX is not the correct format type to download in. I checked hte documentation and it said use only PPTX, XLSX, etc and not to use PBIX
2. The second approach seems to over come the time out but it takes an anormous time to start a download and the download takes several 10s of minutes. This approach also does not seem to be stable as I hit the API URL, if I get a 307 I hit the redirect URL and if this returns a 200 or 202 in about 3-4 minutes, I start receiving the data which takes several minutes. Otherwise it fails, and I hit the initial API again and guide to the redirect url. 
3.  The powershell option also seems to be failing when run directly as a pwoershell script or through python. We are getting a 403 error in this process.

Any idea how we can fix this for a python script. At this point it feels we are chaising our tails because every solution results in a similar issue if not the same one.

Again thanks a ton for replying back on this question.

Hi @BhumitraSharma ,

Thanks for reaching out to Microsoft Fabric Community and for sharing the detailed observations.

Based on the behaviour you described, this is consistent with how the Export Report API handles larger PBIX files. The API is synchronous, and for large files the processing time can exceed what the service allows. Microsoft’s documentation mentions that timeouts can occur during PBIX export and that preferClientRouting can help with routing issues, although it does not specify an exact timeout duration.

Reports - Export Report - REST API (Power BI Power BI REST APIs) | Microsoft Learn

 

The preferClientRouting redirect is expected. It only ensures the request reaches the correct cluster and does not shorten the time needed to generate the PBIX.

 

PowerShell and Python show similar behaviour since both rely on the same synchronous API.

 

If this PBIX needs to be exported reliably, reducing the file size may help by lowering the processing time. If the issue continues, collecting the request ids and timestamps from the failures and raising a support ticket would allow the engineering team to check backend logs and confirm whether the export is hitting a service limitation or something specific to the environment.

 

Please reach out for further assistance,
Thank you.

Hi @BhumitraSharma ,
Just wanted to check if the response provided was helpful. If further assistance is needed, please reach out.

 

Additionally, could you please confirm whether the issue has been addressed through the support ticket with Microsoft?

If the issue is now resolved, we’d greatly appreciate it if you could share any key insights or the resolution here for the benefit of the wider community.

 

Thank you.

Hi @BhumitraSharma,

So Lets try another Approch Using Azure AD app (It should work)

  • For not wasting your time there is a video that shows the first 1 to 5 Steps or this Video  you should watch it Then Make sure your Service Principal:
    • It has API permissions for Power BI Like (Report.Read.All and Workspace.Read.All)

    • Admin consent has been granted

    • In Power BI Admin Portal → Tenant Settings (the Service Principal feature is enabled)

    • The Service Principal is added to the workspace containing your large PBIX as Member or Admin

    • If possible make sure the workspace is Premium this avoids 4 minute timeout issues

Also Before trying the download

  • Test workspace access:
curl -X GET https://api.powerbi.com/v1.0/myorg/groups \
  -H "Authorization: Bearer <ACCESS_TOKEN>"
  • Test report access:
curl -X GET https://api.powerbi.com/v1.0/myorg/groups/<WORKSPACE_ID>/reports/<REPORT_ID> \
  -H "Authorization: Bearer <ACCESS_TOKEN>"
  • Should return 200 OK

 

 

 Also Make sure you are using the correct API

  • DO NOT use ExportTo for PBIX (only supports PPTX/PDF/XLSX)
  • Use the synchronous Export API:

GET https://api.powerbi.com/v1.0/myorg/groups/<WORKSPACE_ID>/reports/<REPORT_ID>/Export?format=PBIX&preferClientRouting=true
  • Ensure to before running 500 MB files test your workflow with 50 or 100 MB PBIX

Final Tip:

  • I am not an Azure hero or Specialist in it So you can go to Azure Community  and ask a question like I want to export Large PBIX File using Azure AD app they will be more helpful than me
if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

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!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI 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.