User Profile
CMAltium
Frequent Visitor
Joined 2 years ago
User Widgets
Contributions
Re: Multiple data source kinds in one custom power query connector
Hi Albert, Below is an example of my code. The flow is as follows: - Authenticate for Nexar using OAuth 2.0. I haven't included all the code for this in the example below, but it works fine. - Call API to retrieve a long URL, which when clicked, downloads a CSV. This URL is truncated by Power BI desktop. - Call tinyUrl API to shorten the long URL. This is where I believe the power connector is unhappy, and in Power BI desktop I get this error: - Open the report as a table. My code is as follows: // // Data Source definition // [DataSource.Kind="Nexar_PKCESample", Publish="Nexar_PKCESample.Publish"] shared Nexar_PKCESample.Contents = (url) => let accessToken = Extension.CurrentCredential()[access_token], url = "https://api.nexardev.com/graphql", contents = GetReport(accessToken) in contents; // // Data Source Kind definition //This part works fine. I haven't included the full authentication code in this example. // Nexar_PKCESample = [ Authentication = [ OAuth = [ // //Authentication for reporting API // StartLogin = StartLogin, FinishLogin = FinishLogin, Refresh = Refresh ] ], Label = Extension.LoadString("DataSourceLabel") ]; //TinyURL URL shortening GetReport = (accessToken) => let //... //Original script to get URL from a different API using the accessToken //... //Long URL from script above longUrl = "https://www.examplelongurl.com", shortUrl = shortenUrl(longUrl) in shortUrl; //Function for URL shortening //This function seems to cause issues as the Power Query Connector requires credentials to be set to call this API too, even though I have my token built in to the function shortenUrl = (longUrl) => let tinyUrl = "https://api.tinyurl.com/create?api_token=<MYTOKEN>", json_data = Json.FromValue([url = longUrl]), response = Web.Contents( tinyUrl, [ Content = json_data, Headers = [#"Content-Type" = "application/json"] ] ), #"JSON" = Json.Document(response), shortUrl = #"JSON"[data][tiny_url] in shortUrl; I tried to make a separate connector for tinyUrl, and when I run that this popup appears: It appears to me that because there are two APIs in use, the credentials for the first do not match the credentials for the second even when my authentication token is provided in the function.626Views0likes0CommentsMultiple data source kinds in one custom power query connector
I have created a connector to access reports from an API with OAuth 2.0, which works fine. However, the API call returns a URL used to retrieve the report, which is truncated by Power BI. I want to use the tinyUrl API to shorten the URL, but am having trouble with errors arising from multiple credentials in one connector. Is there a way to set multiple credentials for different APIs in one connector? I thought about making another DataSourceKind but wasn't sure how that would work.688Views0likes2CommentsRe: Calling two different APIs with different authentication requirements
Hi, I tried your example, but had the same issue as before. I have written a function very similar to the one that you shared. However, when I try and run it within my script which uses an API with different credential requirements, it causes an issue in Power BI Desktop: Here is an example snippet of my code: // // Data Source definition // [DataSource.Kind="Nexar_PKCESample", Publish="Nexar_PKCESample.Publish"] shared Nexar_PKCESample.Contents = (url) => let accessToken = Extension.CurrentCredential()[access_token], url = "https://api.nexardev.com/graphql", contents = GetReport(accessToken) in contents; // // Data Source Kind definition // Nexar_PKCESample = [ Authentication = [ OAuth = [ // //Authentication for reporting API // StartLogin = StartLogin, FinishLogin = FinishLogin, Refresh = Refresh ] ], Label = Extension.LoadString("DataSourceLabel") ]; //TinyURL URL shortening GetReport = (accessToken) => let //... //Original script to get URL from a different API using the accessToken //... //Long URL from script above longUrl = "https://www.examplelongurl.com", shortUrl = shortenUrl(longUrl) in shortUrl; //Script for URL shortening shortenUrl = (longUrl) => let tinyUrl = "https://api.tinyurl.com/create?api_token=<MYTOKEN>", json_data = Json.FromValue([url = longUrl]), response = Web.Contents( tinyUrl, [ Content = json_data, Headers = [#"Content-Type" = "application/json"] ] ), #"JSON" = Json.Document(response), shortUrl = #"JSON"[data][tiny_url] in shortUrl; Here is the script for the self contained connector to tinyUrl: // This file contains your Data Connector logic [Version = "1.0.0"] section tinyUrl; [DataSource.Kind="tinyUrl", Publish="tinyUrl.Publish"] shared tinyUrl.Contents = (optional message as text) => let longUrl="https://123testing.com", tinyUrl = "https://api.tinyurl.com/create?api_token=XcBFxMQDD4cmCQRavoSQdpiBjbdlkOElemeym5ObvwbvcAckIng7IyIejAE1", tinyUrlToken="XcBFxMQDD4cmCQRavoSQdpiBjbdlkOElemeym5ObvwbvcAckIng7IyIejAE1", json_data = Json.FromValue([url = longUrl]), response = Web.Contents( tinyUrl, [ Content = json_data, Headers = [#"Content-Type" = "application/json"] ] ), #"JSON" = Json.Document(response), shortUrl = #"JSON"[data][tiny_url] in shortUrl; // Data Source Kind description tinyUrl = [ Authentication = [ // Key = [], // UsernamePassword = [], // Windows = [], Anonymous = [] ], Label = "tinyUrl connector" ]; // Data Source UI publishing description tinyUrl.Publish = [ Beta = true, Category = "Other", ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") }, LearnMoreUrl = "https://powerbi.microsoft.com/", SourceImage = tinyUrl.Icons, SourceTypeImage = tinyUrl.Icons ]; tinyUrl.Icons = [ Icon16 = { Extension.Contents("tinyUrl16.png"), Extension.Contents("tinyUrl20.png"), Extension.Contents("tinyUrl24.png"), Extension.Contents("tinyUrl32.png") }, Icon32 = { Extension.Contents("tinyUrl32.png"), Extension.Contents("tinyUrl40.png"), Extension.Contents("tinyUrl48.png"), Extension.Contents("tinyUrl64.png") } ]; When I run only that function in its own, self contained connector, I see this: I can set the credentials using "Power Query SDK" > "Set Credentials" in the bottom left corner of Visual Studio. Is there a way to do that programmatically, rather than manually?772Views0likes0CommentsCalling two different APIs with different authentication requirements
Hi, I have set up OAuth 2 in a power query connector to work with refresh tokens, to access reports from an API and show them in a table. This works fine. However, the URL to access the reports is too long, and gets truncated. I have tried to implement tinyUrl's API in a separate function to shorten the URL. This caused an authentication issue, the function does not run, and the connector will fail with "We couldn't authenticate with the credentials provided. Please try again." I then created a new power connector for just URL shortening, and when I try to use the connector, I get the pop up: "Credentials are required to connect to the tinyUrl source. (Source at tinyUrl.)". I can set the credentials using the button "Power Query SDK" > "Set Credential" in the bottom left of Visual Studio. I believe that this manual step is causing the error in my original code. Is there a way to set these credentials programmatically, so when my original code reaches the function for URL shortening, the credentials can be set and the script continues to run. Thank you, Chung823Views0likes3Comments
Data Privacy
Microsoft Fabric Community and Privacy
To learn more about how we manage your data, please review the Microsoft Fabric Community Data Privacy guide.