March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Solved! Go to Solution.
Hello @Laurene,
1. You can use Power Automate to export Power BI reports to Word documents as PDFs, but this may not allow you to update visuals dynamically. (Another approach would be to embed Power BI reports in a Word document using live links)
2. A Python script can be used in conjunction with the Power BI REST API to download the images.
import requests
from requests.auth import HTTPBasicAuth
# Replace with your credentials and Power BI API details
CLIENT_ID = 'your-client-id'
CLIENT_SECRET = 'your-client-secret'
TENANT_ID = 'your-tenant-id'
WORKSPACE_ID = 'your-workspace-id'
REPORT_ID = 'your-report-id'
VISUAL_ID = 'your-visual-id'
API_ENDPOINT = f'https://api.powerbi.com/v1.0/myorg/groups/{WORKSPACE_ID}/reports/{REPORT_ID}/exportToFile'
# Authentication
auth_url = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
auth_params = {
'grant_type': 'client_credentials',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'scope': 'https://graph.microsoft.com/.default'
}
auth_response = requests.post(auth_url, data=auth_params)
access_token = auth_response.json().get('access_token')
# Requesting visual as an image
headers = {
'Authorization': f'Bearer {access_token}'
}
response = requests.get(API_ENDPOINT, headers=headers)
if response.status_code == 200:
with open(f"{VISUAL_ID}.png", 'wb') as f:
f.write(response.content)
print(f"Visual {VISUAL_ID} downloaded as an image.")
else:
print(f"Failed to download visual. Status code: {response.status_code}")
Hope this helps.
Your solution is so great @Sahir_Maharaj
Hi, @Laurene
You can call Power BI's API interface from the tutorial below to export your report to a file.
As you mentioned, there are a few programming languages that you can do that. Super user gives a good sample code.
Export Power BI embedded analytics reports API - Power BI | Microsoft Learn
If you want to get the ID in visual, here there are two official ways to do it:
In addition, you can also check out the following community cases with the same problem, in which there is also a way to get the visual ID:
Solved: identifying visualname in Custom Visuals - Microsoft Fabric Community
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @Laurene,
1. You can use Power Automate to export Power BI reports to Word documents as PDFs, but this may not allow you to update visuals dynamically. (Another approach would be to embed Power BI reports in a Word document using live links)
2. A Python script can be used in conjunction with the Power BI REST API to download the images.
import requests
from requests.auth import HTTPBasicAuth
# Replace with your credentials and Power BI API details
CLIENT_ID = 'your-client-id'
CLIENT_SECRET = 'your-client-secret'
TENANT_ID = 'your-tenant-id'
WORKSPACE_ID = 'your-workspace-id'
REPORT_ID = 'your-report-id'
VISUAL_ID = 'your-visual-id'
API_ENDPOINT = f'https://api.powerbi.com/v1.0/myorg/groups/{WORKSPACE_ID}/reports/{REPORT_ID}/exportToFile'
# Authentication
auth_url = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
auth_params = {
'grant_type': 'client_credentials',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'scope': 'https://graph.microsoft.com/.default'
}
auth_response = requests.post(auth_url, data=auth_params)
access_token = auth_response.json().get('access_token')
# Requesting visual as an image
headers = {
'Authorization': f'Bearer {access_token}'
}
response = requests.get(API_ENDPOINT, headers=headers)
if response.status_code == 200:
with open(f"{VISUAL_ID}.png", 'wb') as f:
f.write(response.content)
print(f"Visual {VISUAL_ID} downloaded as an image.")
else:
print(f"Failed to download visual. Status code: {response.status_code}")
Hope this helps.
Hello,
Thank you very much for your help and your answer! How can I know the visuals id though? My goal is ultimately to automatically fetch the visuals links, so having to manually get the ids kind of defeats the purpose.
Thank you!
Laurene
Your solution is so great @Sahir_Maharaj
Hi, @Laurene
You can call Power BI's API interface from the tutorial below to export your report to a file.
As you mentioned, there are a few programming languages that you can do that. Super user gives a good sample code.
Export Power BI embedded analytics reports API - Power BI | Microsoft Learn
If you want to get the ID in visual, here there are two official ways to do it:
In addition, you can also check out the following community cases with the same problem, in which there is also a way to get the visual ID:
Solved: identifying visualname in Custom Visuals - Microsoft Fabric Community
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
40 | |
26 | |
17 | |
11 | |
10 |
User | Count |
---|---|
58 | |
52 | |
23 | |
14 | |
11 |