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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
pritam121
New Member

Rest API Call from Python

Hi, I have been trying to call the rest API from python but couldn't be able to create the access token for that. hence an unknown error is coming everytime.. Can anyone please help me to get this connection done. 

 

Thanks

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @pritam121 

Based on my previous test and research, if you want to run the Power BI rest API using any tool including Python, you need to first generate an AAD access token in the type of bearer token to put in the request header of any Power BI rest API to run them, for the process of generating an AAD access token in the type of bearer token, please kindly refer to this kind of method, here's the pre-requirement of it.

1 You need to register an AAD application for this :

Create an Azure AD app and service principal in the portal - Microsoft Entra | Microsoft Learn

 

2 You need to call an AAD graph API using the API type like this for your own AAD account:

vyueyunzhmsft_0-1691034055500.png

 

3 For the client ID and client secret you need to get it from the AAD application you created in step 1

Generate new Client Secret and link to key-vault | Microsoft Learn

 

For the guidance from Python side, you can check if this blog can help you also:

How to Use an API with Python (Beginner's Guide) [Python API Tutorial] (rapidapi.com)

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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-yueyunzh-msft
Community Support
Community Support

Hi , @pritam121 

Based on my previous test and research, if you want to run the Power BI rest API using any tool including Python, you need to first generate an AAD access token in the type of bearer token to put in the request header of any Power BI rest API to run them, for the process of generating an AAD access token in the type of bearer token, please kindly refer to this kind of method, here's the pre-requirement of it.

1 You need to register an AAD application for this :

Create an Azure AD app and service principal in the portal - Microsoft Entra | Microsoft Learn

 

2 You need to call an AAD graph API using the API type like this for your own AAD account:

vyueyunzhmsft_0-1691034055500.png

 

3 For the client ID and client secret you need to get it from the AAD application you created in step 1

Generate new Client Secret and link to key-vault | Microsoft Learn

 

For the guidance from Python side, you can check if this blog can help you also:

How to Use an API with Python (Beginner's Guide) [Python API Tutorial] (rapidapi.com)

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Solution Authors