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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

¿how to connect to an API that needs username and password in Power BI Desktop?

Hi, I am currently connecting to the API through Power Query with M Language, in the code I am entering the username and password to obtain the API token and later I will make another query that will serve me for the report.

 

my example is the following:

 
let
vUrlGetToken = "https://my-api-with-security.com/spa/login",
parameters = "{ ""email"": ""user@user.com"", ""password"": ""1234567""}",
Parsed_JSON = Json.Document(parameters),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
Source = Json.Document(Web.Contents(vUrlGetToken,[Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(BuildQueryString) ] )),
vToken = "Bearer "&Source[token],
vUrl ="https://my-api-with-security.com/spa/powerbi/get_list_report",
content = "{
""method"": ""post"",
}",
Origen = Json.Document(Web.Contents(vUrl, [
Headers=[#"Authorization" = vToken, #"Content-Type"="application/json"],
Content=Text.ToBinary(content)
])),
rows = Origen[rows],
in
rows
 

As you can see I am doing: 
parameters = "{ ""email"": ""user@user.com"", ""password"": ""1234567""}",


But I need to find a way to not have to enter the username and password from the M language, there is some way that through Power BI when opening the report, it asks me for the username and password, this username and password is received by the M language in power query and do continue with workflow ?

 
 

Is there any such functionality? and thus not expose the username and password in the Power Query?

 

5 REPLIES 5
lbendlin
Super User
Super User

you already received your Bearer token.  Use it in the subsequent API calls.

jggj
Frequent Visitor

the question is more focused on not being visually the username and password.

 
 
 

Hi @jggj 

 

You may try the query parameter in Power Query. 

Parameters - Power Query | Microsoft Docs

Create a parameter query (Power Query) (microsoft.com)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Store your user name and password in a sharepoint file. Access that file via Power Query Sharepoint Folder connector, read its contents and put it in the query.

 

Beware the Formula Firewall.

jggj
Frequent Visitor

By any chance, do you have an example that applies to what I have already worked on, to guide me. I don't really know where to start. Thanks a lot.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors