Forum Discussion

alexyin1053's avatar
alexyin1053
Helper I
1 year ago
Solved

Get SQL Server Data from Power BI Report Server's Rest API

Dear all,   Currenly we're running on premise power bi report server, while we would like to get one of SQL Server's  table([ReportServer].[dbo].[Users]) by using Power BI Report Server's Rest API....
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi, alexyin1053 

    Your clarification has helped me better understand your needs. You expect to get a list of users with access to each Power BI report. This is available through the API. I wrote a python code:

    key api : Power BI Reports - Get Power BI Report Policies - REST API (Power bi report) | Microsoft Learn

    key api: Power BI Reports - Get Power BI Reports - REST API (Power bi report) | Microsoft Learn

    import requests
    from requests_ntlm import HttpNtlmAuth
    
    url = "http://Yourserver/Reports/api/v2.0/PowerBIReports"
    headers = {
        "accept": "application/json, text/plain, */*",
        "accept-encoding": "gzip, deflate",
        "accept-language": "en-US,en;q=0.9",
        "connection": "keep-alive",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
    }
    
    # replace your username and pwd
    username = ""
    password = ""
    
    response = requests.get(url, headers=headers, auth=HttpNtlmAuth(username, password))
    
    print(response.status_code)
    reportlist = response.json()["value"]
    newlist = []
    newdict = {}
    for item in reportlist:
        newdict = {"id": item["Id"],"ReportName":item["Name"]}
        newlist.append(newdict)
    for i in range(len(newlist)):
        url2 = f"http://YourServer/Reports/api/v2.0/PowerBIReports({newlist[i]["id"]})/Policies"
        response1 = requests.get(url2, headers=headers, auth=HttpNtlmAuth(username, password))
        policies = response1.json()["Policies"]
        newlist[i]["Policies"] = policies
        
    
    print(newlist)

    You should be able to get a dictionary like this (which contains a list of user information accessible for each report):

    You can then use this dictionary for analysis or import into Power BI.

     

     

    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.