I am reading data from a REST API using Power Query. this is my request:
let
url = "https://example",
token = "MyToken",
options = [Headers=[Authorization="Bearer " & token]],
contents = Web.Contents(url, options)
in
contents
I have to authorise via bearer token, which works like a charm with the above code.
However if I change my code slightly:
This part is resolved by Davide's answer, it works with the uppercase From
let
url = "example",
token = Text.from("MyToken"),
options = [Headers=[Authorization="Bearer " & token]],
contents = Web.Contents(url, options)
in
contents
the Web.Contents
request fails with an
[Expression.Error] The import Text.from matches no exports. Did you miss a module reference?
Another option I tried is to read from a cell:
let
url = "https://example",
token = Excel.CurrentWorkbook(){[Name="MyToken"]}[Content]{0}[Column1],
options = [Headers=[Authorization="Bearer " & token]],
contents = Web.Contents(url, options)
in
contents
In this case the Web.Content
request fails with
An on-premises data gateway is required to connect.
The only difference here is, that in the first case token
is a static string, while in both the adjusted code examples it is a dynamic string, because it now is the output of a runtime function.
I have to read the token from an external source, so keeping it as static string in the script is not an option.
Any idea how to make this work would be appreciated.
Found an answer by chance: