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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
CMAltium
Frequent Visitor

Multiple 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.

2 REPLIES 2
Anonymous
Not applicable

Hi @CMAltium ,
Based on your description, Power Query does not directly support setting up multiple different credentials for the same connector. You can use parameters to manage different credentials. You can create a parameter table with credentials for different APIs and then use those parameters in your query.
You can create a custom function to do this

let
    Source = (username as text, password as text) as table =>
    let
        // use username and password to send API request
    in
        // return data list
in
    Source

 

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly


 

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:

CMAltium_0-1722329104172.png

 

- 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:

CMAltium_1-1722329141068.png

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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.