Forum Discussion
Using Custom Data Connector to read Local .txt File
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.
13 Replies
- lbendlinSuper User
Are you planning to run this only on Power BI Desktop or do you eventually want to use your custom connector in the service?
- status5009Frequent Visitor
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.
- lbendlinSuper User
Would placing these files on a SharePoint or OneDrive instead be an option for you? It would save you enormous amounts of future headaches.