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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Power Rest API Authorization Token Error

Hello, I am trying to get an authroization token from Azure Service Principal using Postman and Power Query so I can query the Power BI Rest API but I keep getting an error. I cannot use a username and password to pull the data so we have set up a code and clientsecret. Has anyone had any experience setting it up? I have tried the configuration in POSTMAN and Power Quer

 

The URL I am using is: https://login.microsoftonline.com/<tenantid>/oauth2/authorize

Other parameters included in the body:

client_id

code

client_secret

grant_type: authorization_code

response_mode: query

resource: https://analysis.windows.net/powerbi/api

 

mnayar_0-1623696875023.png

 

I have also tried the following url  https://login.microsoftonline.com/<tenantid>/oauth2/token

and I get an invalid_grant error

mnayar_6-1623697591810.png

 

 

 

 

Other values set in the App Registeration are:

mnayar_1-1623697135299.png

mnayar_2-1623697179139.png

mnayar_3-1623697208268.png

 

I am using the following code in Power Query

mnayar_4-1623697369505.png

 

 

 

 

 

 

 

11 REPLIES 11
Watsky
Solution Sage
Solution Sage

Hey @Anonymous  I haven't setup using authorization_code grant types before, but I have used client_secrets. Have you tried changing your grant_type to client_credentials? Try changing your grant type on https://login.microsoftonline.com/<tenantid>/oauth2/token

see if that works for you. 

 

If that doesn't work for you take a look at this info

 

Microsoft identity platform and OAuth 2.0 authorization code flow - Microsoft identity platform | Microsoft Docs

 

You see towards the middle of the page how to use authorization_code grant types but it appears to have different keys than you're currently using.


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

Hello Watsky, When you mentioned grant_type client_credentials does that require username and password? 

No, these are the only keys I have listed when I run it in Postman 

 

Watsky_0-1623781317937.png

Watsky_2-1623781592028.png

 


 


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

Can you provide screenshot of the values you use for the above attributed?

Sure at least everything but my client_id and secret. Also, I'm on GCC so my resource is a bit different, so no need copying that over.

apikey.png

 


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

So I was able to get an authorization code, but when I use it in within Power BI, it expects me to sign in, that shouldnt be requirement right?

 

mnayar_1-1623783374644.png

mnayar_2-1623783404947.png

 

 

 

 

It shouldn't be I just tested and I have my credentials set to Anoynmous.

 

Watsky_0-1623795067340.png

 


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

Could you share your Power Query Code for getting token and using that token in the call to get workspaces just so that I can confirm I got everything in there? Also, can you confirm the settings in Azure I have made?

Watsky_0-1623937375998.png

 as for your Azure settings. Has an admin granted privledges for the permissions? Looking at mine I have a granted/not granted by all of the permissions.

 

Watsky_1-1623937520528.png


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up! ?
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

 


Did my answer(s) help you? Give it a kudos by clicking the Thumbs Up!
Did my post answer your question(s)? Mark my post as a solution. This will help others find the solution.

Proud to be a Super User!

Anonymous
Not applicable

Everything above is the same. I get an unauthozed 401 message in Postman when I use the authorization code generated in Power BI. My guess is there is something different in Azure config. 

 

mnayar_0-1623952438645.png

 

Hi @Anonymous.

I'd like to suggest you check if you used the same account on the power bi side which assigned the api permissions on the Azure side.

For this scenario, you can also contact azure support to trace the requests to get further information and support for troubleshooting.

BTW, it seems like you are work with admin API, have you assign the power bi admin permission on the test account?

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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