I am looping across power bi reports>pages>visuals and then fields within them , the code to retrieve pages works fine, however there is an issue with visual url, in Visual response it says - No HTTP request was found that matches the url.
I get an issue in below code
visuals_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/pages/{page_name}/visuals"
visuals_response = requests.get(visuals_url, headers=headers)
Below is the full block of code, is there an issue with visuals_url in below code?
import requests
# Define the necessary variables
workspace_id = "your_workspace_id"
report_id = "your_report_id"
access_token = "your_access_token"
# Define the headers with the access token
headers = {
"Authorization": f"Bearer {access_token}"
}
# Define the URL for pages
pages_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/pages"
# Send a GET request to retrieve pages
response = requests.get(pages_url, headers=headers)
pages = response.json()["value"]
# Extract page information
for page in pages:
page_name = page["name"]
page_display_name = page["displayName"]
print(f"Page Name: {page_name}, Display Name: {page_display_name}")
# Define the URL for visuals within the current page
visuals_url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/reports/{report_id}/pages/{page_name}/visuals"
# Send a GET request to retrieve visuals
visuals_response = requests.get(visuals_url, headers=headers)
visuals = visuals_response.json()["value"]
# Extract visual information
for visual in visuals:
visual_name = visual["name"]
visual_display_name = visual["displayName"]
print(f"Visual Name: {visual_name}, Display Name: {visual_display_name}")
Instead of using Rest API you can use powerbiclient package. Follow the following steps to get visuals and fields within report page:
Install power bi clients
pip install powerbiclient
Get the active page from the embedded report.
To get the a specific visual on the page use the visuals_on_page() from powerbiclient.
Once the visual is selected, use the export_visual_data() from the powerbiclient to get the data fields of the visual.
Output image: