How to enable scheduled refresh for your custom connector

Here is a post that is long overdue as the functionality has been available for almost a year now. Today we will enable scheduled refresh to the Strava custom connector I build before.

The trick to this is that we need to extend the code of the Strava connector with a “TestConnection” function as is described here. This will allow the Power BI gateway to know how to test the connection.

Of course we will start with getting the latest code from the GitHub repo.

Now all we have to add is a method that will tell Power BI how to test the connection. In my case it was just adding this line of code so going from:

Strava = [
Authentication = [
OAuth = StartLogin = StartLogin, FinishLogin = FinishLogin, Label = Extension.LoadString("AuthenticationLabel")
],
Label = Extension.LoadString("DataSourceLabel")
];

To

Strava = [
TestConnection = (dataSourcePath) => { "Strava.Contents" },
Authentication = [
OAuth = StartLogin = StartLogin, FinishLogin = FinishLogin, Label = Extension.LoadString("AuthenticationLabel")
],
Label = Extension.LoadString("DataSourceLabel")
];

This adds a way for Power BI to know what function to use when testing a connection. This is needed for the Power BI to refresh the dataset. Power BI needs to know if it can refresh before you schedule it. This only works through the personal GW though as this is a custom connector that has not been verified. Let’s set that up. First we turn on Custom connectors in the GW. Then I take the MEZ file that I got as build output from Visual Studio solution and copy it to the Personal GW folder as specified in the GW setup.

As you can see it is now recognized by the gateway. Next we upload the Power BI desktop file to Power BI and set the credentials there:

Now I can set them:

Sign in will pop up the Strava sign in and will request for access.

Now the refresh starts running and we are good to go 🙂

This very small addition now enables your dashboards and reports to always be up to date automatically :). To play with it download the connector here on Github.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.