<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Custom Connector Issues and Caching in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/490151#M15013</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/77079"&gt;@rmonfort&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to&amp;nbsp;&lt;A href="https://github.com/Microsoft/DataConnectors/blob/master/docs/m-extensions.md#authentication-kinds" target="_self"&gt;docs/m-extensions.md#authentication-kinds&lt;/A&gt;. The parameters "&lt;CODE&gt;Refresh" and "Logout" could help.&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;Authentication = [
    OAuth = [
        StartLogin = StartLogin,
        FinishLogin = FinishLogin,
        &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Refresh = Refresh,
        Logout = Logout&lt;/STRONG&gt;&lt;/FONT&gt;
    ],
    Key = [],
    UsernamePassword = [],
    Windows = [],
    Implicit = []
]&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;Dale&lt;/P&gt;</description>
    <pubDate>Wed, 15 Aug 2018 09:41:07 GMT</pubDate>
    <dc:creator>v-jiascu-msft</dc:creator>
    <dc:date>2018-08-15T09:41:07Z</dc:date>
    <item>
      <title>Custom Connector Issues and Caching</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/489314#M14993</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;// This file contains Data Connector logic
section DataConnector;

[DataSource.Kind="DataConnector", Publish="DataConnector.Publish"]
shared DataConnector.Contents = (Url as text, SavedviewId as text) =&amp;gt;
	let
	  Credential = Extension.CurrentCredential(),
	  split = Text.Split(Credential[Username],"#"),
	  Username = List.First(split),
	  Api_key = List.Last(split),
	  Source = Json.Document(Web.Contents(Url&amp;amp;"/bulkapi/token", [Headers=[#"username"=Username, #"password"=Extension.CurrentCredential()[Password], #"apikey"=Api_key]])),
	  SessionToken = Source[Result][AccessToken],
	  ApiUrl = Url&amp;amp;"/Bulkapi/savedviews/"&amp;amp;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") }
];&lt;/PRE&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2018 14:07:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/489314#M14993</guid>
      <dc:creator>rmonfort</dc:creator>
      <dc:date>2018-08-14T14:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Connector Issues and Caching</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/490151#M15013</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/77079"&gt;@rmonfort&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to&amp;nbsp;&lt;A href="https://github.com/Microsoft/DataConnectors/blob/master/docs/m-extensions.md#authentication-kinds" target="_self"&gt;docs/m-extensions.md#authentication-kinds&lt;/A&gt;. The parameters "&lt;CODE&gt;Refresh" and "Logout" could help.&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;Authentication = [
    OAuth = [
        StartLogin = StartLogin,
        FinishLogin = FinishLogin,
        &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Refresh = Refresh,
        Logout = Logout&lt;/STRONG&gt;&lt;/FONT&gt;
    ],
    Key = [],
    UsernamePassword = [],
    Windows = [],
    Implicit = []
]&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;Dale&lt;/P&gt;</description>
      <pubDate>Wed, 15 Aug 2018 09:41:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/490151#M15013</guid>
      <dc:creator>v-jiascu-msft</dc:creator>
      <dc:date>2018-08-15T09:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Connector Issues and Caching</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/1590086#M27177</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/77079"&gt;@rmonfort&lt;/a&gt;&amp;nbsp; I am facing the exact same issue, have you been able to solve it?&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/28904"&gt;@v-jiascu-msft&lt;/a&gt;&amp;nbsp;, we are both using UsernamePassword authentication, is there a similar refresh/logout functionality for this auth?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 17:19:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Custom-Connector-Issues-and-Caching/m-p/1590086#M27177</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-01-11T17:19:05Z</dc:date>
    </item>
  </channel>
</rss>

