Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
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?
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
User | Count |
---|---|
5 | |
4 | |
4 | |
2 | |
2 |
User | Count |
---|---|
8 | |
4 | |
4 | |
4 | |
3 |