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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
yazdanb
Frequent Visitor

Can I expand my Python script to retrieve information about visuals and datasets on a page?

Hey everyone! I currently have a Python script that makes an API call to my team's workspace to retrieve two things:

 

1. A list of all reports/dashboards that current exist and are being worked on

2. A sublist of every page within each report/dashboard

 

My next requirement is to expand this script to retrieve the visual information off of each page - the number of visuals on the page, which type of visuals/elements are they, what data sources are they connected to, how many slicers and buttons are there, where is everything positioned/placed etc. The goal is to have an executable that retrieve and consolidate the information of our workspace in a simple, text-based format so we have all our "metadata" in one place to analyze and keep track of.


Here is my script so far (assuming imports and constants):

def getReportsInGroup(GROUP_ID):
    API_URL = f"https://api.powerbi.com/v1.0/myorg/groups/{GROUP_ID}/reports"
    headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
    response = requests.get(API_URL, headers=headers)

    if response.status_code == 200:
        print("Retrieved report metadata:")
        reports = response.json()['value']
        
        for report in reports:
            print(f"{report['name']} | Dataset ID = {report['id']}")
            getPagesInReport(report['id'])
    
    else:
        print(f"Failed to retrieve metadata. Status code: {response.status_code}")
        try:
            error_content = response.json()
            print(json.dumps(error_content, indent=4))
        except requests.exceptions.JSONDecodeError:
            print("No JSON response content.")
            print(f"Response text: {response.text}")

def getPagesInReport(DATASET_ID):
    API_URL = f"https://api.powerbi.com/v1.0/myorg/groups/{GROUP_ID}/reports/{DATASET_ID}/pages"
    headers = {"Authorization": f"Bearer {ACCESS_TOKEN}"}
    response = requests.get(API_URL, headers=headers)

    if response.status_code == 200:
        pages = response.json()['value']
        sortedPages = sorted(pages, key=lambda x: x['order'])
        
        for page in sortedPages:
            print(f"--> {page['order']}) {page['displayName']}")
    else:
        print(f"Failed to retrieve metadata. Status code: {response.status_code}")
        try:
            error_content = response.json()
            print(json.dumps(error_content, indent=4))
        except requests.exceptions.JSONDecodeError:
            print("No JSON response content.")
            print(f"Response text: {response.text}")

 

Is it possible to continue using Python methods to get the information I am looking for? I have looked up some idea and saw that some people had luck with embedding reports and running JS on it to get information on what the user actually gets to see since the API calls themselves would not render the same dashboard. I would like to keep it simple, but understand that that is not always possible! Any guidance, tips, and leads will be appreciated! Thank you!

1 ACCEPTED SOLUTION

The console is the standard web browser console (F12/dev tools)

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

Any particular reason for not using the sempy library?

 

Semantic link propagation with SemPy - Microsoft Fabric | Microsoft Learn

I was not aware it existed. Thanks for the suggestion. However, I don't see any documentation to get the info on the visuals being shown on a page 😞

sempy.fabric.TOMWrapper class | Microsoft Learn

 

Also look into the Embedded Analytics Playground, it has sample code for enumerating report pages and visuals.

https://playground.powerbi.com/

Thank you Ibendlin! I have been trying to use the Embedded Analytics Playground, but there does not seem to be any console where I can see any output. If I try any event-related code (like opening a Print dialog or Saving the report), there is no issue. But if try something like logging the pages in the report, there is no console that appears to see that output. Is this a common issue?

The console is the standard web browser console (F12/dev tools)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.