Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I am trying to read the contents of a local text, but when I try to use my custom connector in Power BI, it keeps giving me the error "Please specify how to connect". I have tried the different authentication types but none of them have worked.
[DataSource.Kind = "LocalFile", Publish = "LocalFile.Publish"]
shared LocalFile.Contents = () =>
let
path = "C:\Users\User\Documents\key.txt",
ttemp = File.Contents("C:\Users\User\Documents\key.txt"),
token = Text.FromBinary(ttemp),
headers = [#"Content-Type"="application/json", #"Authorization"=token],
result = Json.Document(Web.Contents(url, [Headers = headers])),
in
result;
LocalFile = [
Authentication = [
UsernamePassword = [],
Windows = [],
Anonymous = []
]
];
I'm not sure how to resolve this issue. I am able to read a local file by creating a Windows credential with the path to the file for use in the .pq file, but I can't find this option in the data connector itself.
Are you planning to run this only on Power BI Desktop or do you eventually want to use your custom connector in the service?
I want to use my custom connector in Power BI Desktop to make calling the API I plan on using easier.
I have gotten it to work normally in Power BI using the query editor inside it or the import Text/CSV data source, but I wanted to see if I could have this custom connector read a text file to get a user's authentication token without having to do those other ways.
Would placing these files on a SharePoint or OneDrive instead be an option for you? It would save you enormous amounts of future headaches.
I could but the reason I wanted to use a local file is to avoid the step of having the user sign into anything.
Do you know how I would go about accessing the file either through their local file system or OneDrive so I can compare the two?
Use the "SharePoint Folder" connector for OneDrive.
Sadly, Azure Keyvault is not a viable option yet.
Is there a way I could replicate the functionality of the SharePoint Folder connector inside a custom connector using the Power Query SDK?
Ideally with my custom connector the idea is the user would only need to include whatever parameters they want in the HTTP request and it would handle getting the authorization key from either the text file located on their computer or OneDrive.
You may be trying to do too much. Power Query does not take kindly to overly dynamic data sources.
What's the actual business scenario?
We are trying to use Power BI to import our internal data for people to analyze it. I got the functionality to retrieve the data working fine. It is just the authorization that we are trying to figure out.
Ideally we want to make the authorization as simple as possible, where the user only needs to add whatever parameters they want when retrieving the data and that's all they need to do. The way authorization was going to be handled that way was by having the custom connector read a file on the user's computer that had their token and pass that along with their request.
The main question I have is it possible to read a file using a custom connector and if so how do you do it?
My guess is that this is not possible with a custom connector. But it may not be required. If they have the parameter file on their PC then you can access that via the Folder connector. Of course this will never refresh on the service but that doesn't seem to be your aim anyway.
I talked to Microsoft support about it and they confirmed you cannot read a local file.
For reading files from OneDrive, what would the code for the custom connector look like? I am using Web.Contents with the path found on OneDrive but it gives me "We couldn't authenticate with the credentials proved. Please try again."
Here is my code for trying to read the file on OneDrive:
```
Not Web.Contents - Use SharePoint.Files
I changed it to SharePoint.files and used one of my sharepoint sites but it gives the original error of "Please specify how to connect" when I try to do the Windows authentication.
I put the same query into Power BI normally and it gives me an option to sign in with my Microsoft account. Is there a way to do that on the custom connector or is it something else.
Sharepoint authenticates via OAUTH2. You can use AAD in your custom connector.
Windows Auth would only be applicable if your SharePoint were on-premise.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
7 | |
2 | |
2 | |
1 |
User | Count |
---|---|
3 | |
3 | |
3 | |
2 | |
2 |