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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bsmithUI
Advocate I
Advocate I

Power BI API

Has anyone used the Power BI Rest API's as a data source in Power BI? I am looking to use it for some administrative reports. I am trying to get authenticated...I thought maybe Organizational Account, or Anonymous may pop open an O365 login window, but neither worked. I also tried Windows account thinking it might pass my Azure AD credentials to Power BI, but that didn't work either.

 

Any ideas? I am specifically thinking of this endpoint as a starting point: https://docs.microsoft.com/en-us/rest/api/power-bi/admin/groups_getgroupsasadmin 

 

Thanks for any ideas! 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @bsmithUI,

 

We need the access token to authenticate the request and do it like below. 

Power-BI-API

The problem is the token only survives 1 hour or more. It's hard to refresh the request. Maybe you can try the Python script with ADAL.

from adal import AuthenticationContext
import requests
import json
import pandas as pd


client_id = "a301********-98fe1dcde27e"  # application id
resource_uri = "https://analysis.windows.net/powerbi/api"  
user_name = "d*@microsoft.com"
user_password = "****"

auth_context = AuthenticationContext("https://login.microsoftonline.com/Your_tenant_name")
token_response = auth_context.acquire_token_with_username_password(resource_uri, user_name, user_password, client_id)
token = "Bearer " + token_response["accessToken"]

api_url = "https://api.powerbi.com/v1.0/myorg/admin/groups"
headers = {"Authorization": token}
r = requests.get(api_url, headers = headers)

result = pd.io.json.json_normalize(json.loads(r.text)["value"])

Power-BI-API2

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-jiascu-msft
Employee
Employee

Hi @bsmithUI,

 

We need the access token to authenticate the request and do it like below. 

Power-BI-API

The problem is the token only survives 1 hour or more. It's hard to refresh the request. Maybe you can try the Python script with ADAL.

from adal import AuthenticationContext
import requests
import json
import pandas as pd


client_id = "a301********-98fe1dcde27e"  # application id
resource_uri = "https://analysis.windows.net/powerbi/api"  
user_name = "d*@microsoft.com"
user_password = "****"

auth_context = AuthenticationContext("https://login.microsoftonline.com/Your_tenant_name")
token_response = auth_context.acquire_token_with_username_password(resource_uri, user_name, user_password, client_id)
token = "Bearer " + token_response["accessToken"]

api_url = "https://api.powerbi.com/v1.0/myorg/admin/groups"
headers = {"Authorization": token}
r = requests.get(api_url, headers = headers)

result = pd.io.json.json_normalize(json.loads(r.text)["value"])

Power-BI-API2

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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