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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.