This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
I am building a custom connector.
All requests require a jwt, which expires after 15 minutes.
I get a jwt by calling a /login endpoint. I am able to get the token, and make the requests, but can't enable automatic refreshes. Tried following a tutorial, but it does not work.
I am pretty sure it is because I don't tell PBI how to get the new token on refresh.
query.pq
let
result = Youandx_v2.Contents()
in
result
.pq file, where I declare the "TestConnection", where I think something is wrong. Should I instead do something with my getJwt function?
Youandx_v2 = [
TestConnection = (dataSourcePath) => { "Youandx.Contents" },
Authentication = [
UsernamePassword = [
UsernameLabel = "Username",
PasswordLabel = "Password"
]
],
Label = Extension.LoadString("DataSourceLabel")
];
Another place in same file:
[DataSource.Kind="Youandx_v2", Publish="Youandx_v2.Publish"]
shared Youandx_v2.Contents = () =>
let
jwt = getJwt(),
navTable = navTable(jwt)
in
navTable;
navTable function
navTable = (jwt as text) as table =>
let
bookingTable = getBookings(jwt),
source = #table({"Name", "Data", "ItemKind", "ItemName", "IsLeaf"}, {
{"Bookings", bookingTable, "Table", "Table", true},
{"Speakers", getSpeakers(jwt), "Table", "Table", true} ,
{"Products", getProducts(jwt), "Table", "Table", true},
{"Invoices", getInvoices(bookingTable), "Table", "Table", true},
{"Line Items", getLineItems(bookingTable), "Table", "Table", true},
{"Plans", getPlans(jwt), "Table", "Table", true},
{"Speaker Account", getSpeakerAccounts(jwt), "Table", "Table", true}
}),
navTable = Table.ToNavigationTable(source, {"Name"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
in
navTable;
getJwt
getJwt = () =>
let
username = Extension.CurrentCredential()[Username],
password = Extension.CurrentCredential()[Password],
URL = "https://www.youandx.com/api/v1/login",
headers = [
#"Content-Type"="application/json"
],
bodyData = Json.FromValue([tmode = 2, hold = 0, email = username, password = password]),
web = Web.Contents(URL, [ Content = bodyData, Headers = headers, ManualStatusHandling = {404, 400}]),
result = Json.Document(web),
first = Record.ToTable(result),
Value = first{1}[Value],
jwt = Value[jwt]
in
jwt;
As you can see, I get a jwt, and pass it on to navTable and then each of the functions, for example getBookings. But how do I make sure, that the getJwt function is called upon refresh?
Thanks.
EDIT: This is the message I get in the Power BI Web interface when trying to refresh the data: "Unable to refresh the model (id=3228545) because it references an unsupported data source."
Solved! Go to Solution.
Hi @FrederikB ,
Please try below code to decode JWT token in custom connector.
let
Token = "<snip>",
Base64Url.Decode = (s) => Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") & {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
Parts
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @FrederikB ,
Please try below code to decode JWT token in custom connector.
let
Token = "<snip>",
Base64Url.Decode = (s) => Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") & {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
Parts
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |