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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

How to convert API call with credentials

Dear, 

I have a Dataverse DataFlow that connects to a third party API, which uses simple authentication.

In the first part, I get the accesstoken by putting my email address and password in the body:

AccessToken = let
  GetJson = Json.Document(Web.Contents("https://xxxxx.com/api/v2/users/me/login", [Headers=[Accept="application/json", #"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"], Content=Text.ToBinary("email=xxxxxxxxxx&password=xxxxxxxxxxx")])),
  data = GetJson[data],
  #"Converted to Table" = Record.ToTable(data),
  #"Filtered Rows" = Table.SelectRows(#"Converted to Table", each [Name] = "accessToken"),
  Value = #"Filtered Rows"{0}[Value]
in Value

In the second part, I use the accesstoken to call an API request:

let
      AccesTokenvalue = AccessToken,
      Source = Json.Document(Web.Contents("https://xxxxxxxx.com/api/v2/getdata", [Headers=[Authorization="Bearer " & AccesTokenvalue]])),
        data = Source[data]
    in
        data
in
  data;

How can I convert this to a query where the credentials can be taken out of the query code, so that the password can remain hidden for users looking into the query?
Thanks,

Koen

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Not sure how ofter your token needs to be refreshed, but one way would be to create a Dataflow with your token query, and then use that Dataflow as the source for the token.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,

 

Would that mean that I somehow save the result of the first "accesstoken" dataflow somewhere in Dataverse? And then I should use that in the "real" dataflow?

If that's the case, I have not yet found a way to call Dataverse data in a dataflow, I probably missed the correct documentation for that somehow; can you point me to documentation / examples of your suggestion?

 

The token is only valid for a two minutes; I need to call the API every five minutes...

 

Thanks,Koen

I was proposing to use a Dataflow that only you had access to (to secure the login info), and using the output of that in a second dataflow that holds the actual data.  Given your 2 and 5 minute requirements, I don't think that would work well.  I don't know a good way to do what you are looking to do. 

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,
Regardless of the fact it will not help in this particular case, I am still curious how you would "use the output" of one dataflow in another dataflow? Where would you store this output, and how would you fetch it in the other dataflow?
I will continue looking for another solution for my original question.

Thanks,

Koen

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.