Forum Discussion
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):
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
- angeloolaHelper I
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?