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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jgarcia_new
Frequent Visitor

¿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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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