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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
gilbertendaya
Helper IV
Helper IV

Get authorization token from API url

How can I get the authorization token value? I'm using advanced editor in power BI desktop.

I do have the generating token URL also the credentials (user and password).

 

let

GetJson = Web.Contents("<URL>",
[
Headers = [#"Accept"="application/json",
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content = Text.ToBinary("username=<username>&password=<password>&grant_type=password")
]
),
FormatAsJson = Json.Document(GetJson),
#"Converted to Table" = Record.ToTable(FormatAsJson),
#"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"Data"}, {"Data"})
in
#"Expanded Value"

@Anonymous  @amitchandak @tonmcg @ImkeF 

13 REPLIES 13
amitchandak
Super User
Super User

Thank you for the response @amitchandak but I still don't get it.

What is wrong with my M-query?

Please advise.

 

Thank you.

@gilbertendaya , refer the m code used in

https://chris.koester.io/index.php/2015/07/16/get-data-from-twitter-api-with-power-query/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak I saw this but it is using client id instead of username/password 😞

@ImkeF , any suggestions on this

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @gilbertendaya ,

if you're trying to create an oauth flow in Power Query, you need to create a custom connetor, I'm afraid.
You can find some details on the auth-part here: https://docs.microsoft.com/en-us/power-query/handlingauthentication

This gives a good overview of the steps involved to create a custom connector: https://jussiroine.com/2019/02/building-a-custom-connector-for-power-bi-that-supports-oauth2-to-visu... 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

hi @ImkeF thank you for the reply. Is there no easy way in M-query to do this?  

hi @ImkeF and @amitchandak 
do you know how to convert this to M-query?

 

{
    "limit"10,
    "aggregate": [
        {
            "$sort": {
                "dateProcessed"-1
            }
        },
        {
            "$match": {
               
            }
        }
    ]
}
 
This is for the body.

Hi @gilbertendaya 

you can simply wrap it into a Json.Document-formula if you escape the quotes like so:

 

 

Json.Document( "{ ""limit"" : 10 , ""aggregate"" : [ { ""$sort"" : { ""dateProcessed"" : -1 } }, { ""$match"" : { } } ]}")

 

 

If you have oauth, there is no simpler way in PQ, unfortunately.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

image1.JPG

hi @ImkeF @amitchandak  sorry again for the questions. Please see attached image. I was able to get the token and assigned it to a variable: authKey2 for Bearer Token.

 

Also added the body.

I encountered the error:

 

image2.JPG

 

What is this error? Please advise.

Thank you always.

Hi @gilbertendaya ,

this is an authentication error.

I can only repeat that to my knowledge you cannot create an oauth flow without a custom connector in Power Query.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

sorry to know that @ImkeF  😞 
but I was able to do that from before
https://community.powerbi.com/t5/Desktop/Error-in-getting-POST-request-in-an-API/td-p/1026143/page/2

I just don't know how to do it again 😞

Hi @gilbertendaya ,

sorry to hear. But the link you've provided does contain nothing that relates to authentication. So don't know how I could help here.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.