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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
angeloola
Helper I
Helper I

Bearer Token as Parameter/Variable in Power Query M

Hello (not sure if my last post sent through).

 

I am calling an API service in Power BI and need to authenticate using Authorization header and Bearer Token. I need to fetch a new token weekly.

 

Right now, the token value is hard-coded into my Advanced Editor code for each endpoint (see sample code below), but I would like to call a parameter for this instead. I've tried using standard parameter syntax, but am having trouble.

 

Here is the current M code that is calling the API: 

let
Source = Json.Document(Web.Contents("Request URL", [Headers=[Authorization="Bearer eyJhbGciOiJub25lIiwi...."]])),
Data = Source[Data],
#"Converted to Table" = Record.ToTable(Data),
Value = #"Converted to Table"{0}[Value],
#"Converted to Table1" = Table.FromList(Value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table1", "Column1", {"id", "name"}, {"id", "name"})
in
#"Expanded Column1"

 

I have set up a parameter for the Bearer Token and want to feed that into the code above (see red bold text):

angeloola_0-1597166171785.png

 

Can someone help me out with the syntax? How can I modify the M to accept the parameter value for my token?

 

Thank you!!

 

4 REPLIES 4

Thanks for the reply, but I can get the token no problem - what I really need is just the syntax to load the parameter value into the Authorization header value in the Advanced Editor. Can you help with that?

@angeloola  did you ever get this to work? I have the same problem. I have the powerquery returning a token but I want to store that in a variable that can be used by other tables.

Hello, I'm very interested about this subject.

I don't use embed power bi, in query, I am using 2 different acess token about the saas application where the data are stored.

The answer of your question : look this video, I'm sure you'll find the solution of your problem.

https://www.youtube.com/watch?v=2RZkc_qrV1g

And be careful about this: https://docs.microsoft.com/en-us/power-bi/admin/desktop-privacy-levels

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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