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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
rmonfort
Regular Visitor

Custom Connector Issues and Caching

Greetings,

 

We're using a rest API to get data from our application into Power BI. Our original query would just retrieve a token and use that token to retrieve a dataset.

 

let
    Source = Json.Document(Web.Contents("http://localhost/crm151/bulkapi/Token", [Headers=[username="myusername", password="mypassword", apikey="myapikey"]])),
    SessionToken = Source[Result][AccessToken],
    ApiUrl = "http://localhost/crm151/Bulkapi/savedviews/24113",
    Options = [Headers =[#"sessiontoken"=SessionToken]],
    Result = Csv.Document(Web.Contents(ApiUrl , Options))
in
    Result

Next we needed to create a custom data connector so that it is much easier for the end user to use, and give them the option to select their dataset by id.

 

// This file contains Data Connector logic
section DataConnector;

[DataSource.Kind="DataConnector", Publish="DataConnector.Publish"]
shared DataConnector.Contents = (Url as text, SavedviewId as text) =>
	let
	  Credential = Extension.CurrentCredential(),
	  split = Text.Split(Credential[Username],"#"),
	  Username = List.First(split),
	  Api_key = List.Last(split),
	  Source = Json.Document(Web.Contents(Url&"/bulkapi/token", [Headers=[#"username"=Username, #"password"=Extension.CurrentCredential()[Password], #"apikey"=Api_key]])),
	  SessionToken = Source[Result][AccessToken],
	  ApiUrl = Url&"/Bulkapi/savedviews/"&SavedviewId,
	  Options = [Headers =[#"sessiontoken"=SessionToken]],
	  Result = Csv.Document(Web.Contents(ApiUrl , Options))
	in
		Result;

// Data Source Kind description
DataConnector = [
	Authentication = [
		// Key = [],
		UsernamePassword = [
		Label = "Authentication",
		UsernameLabel = "Username#APIKey (Enter Username and APIKey seperated by '#')"
		]
		// Windows = [],
		//Implicit = []
	],
	Label = Extension.LoadString("DataSourceLabel")
];

// Data Source UI publishing description
DataConnector.Publish = [
	Beta = true,
	Category = "Other",
	ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
	LearnMoreUrl = "https://powerbi.microsoft.com/",
	SourceImage = DataConnector.Icons,
	SourceTypeImage = DataConnector.Icons
];

DataConnector.Icons = [
	Icon16 = { Extension.Contents("DataConnector16.png"), Extension.Contents("DataConnector20.png"), Extension.Contents("DataConnector24.png"), Extension.Contents("DataConnector32.png") },
	Icon32 = { Extension.Contents("DataConnector32.png"), Extension.Contents("DataConnector40.png"), Extension.Contents("DataConnector48.png"), Extension.Contents("DataConnector64.png") }
];

At first this works perfectly fine. However, after session tokens start expiring we run into issues. When I look at Fiddler, I noticed that it's using an old session token and not retrieving a fresh session token. Just to make sure it's not an issue on my API's end, I ran the original query script and it worked fine. When I clear Power BI's cache, the data connector works again, however, once the session tokens start to expire I run into the same issues. 

 

Is there a way to make sure the data connector is retrieving a fresh session token each time and not refer to cached information? Any suggestions would be greatly appreciated. 

 

 

2 REPLIES 2
Anonymous
Not applicable

Hi there,

 

@rmonfort  I am facing the exact same issue, have you been able to solve it? @v-jiascu-msft , we are both using UsernamePassword authentication, is there a similar refresh/logout functionality for this auth?

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @rmonfort,

 

Please refer to docs/m-extensions.md#authentication-kinds. The parameters "Refresh" and "Logout" could help.

Authentication = [
    OAuth = [
        StartLogin = StartLogin,
        FinishLogin = FinishLogin,
        Refresh = Refresh,
        Logout = Logout
    ],
    Key = [],
    UsernamePassword = [],
    Windows = [],
    Implicit = []
]

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.