Power BI will prompt you to authenticate and will provide multiple options. Just pick the one called "Basic" and enter the username and password. That should automatically insert the base64 encoded username/password in the authentication header.
Thanks for the information, I gave it a try and it didn't work, when prompting for credentials and selecting basic and entering Username and Password it did not work. However I was able to get the following code to work.
Note: I just had to set the Data Source to Anonymous
let actualUrl = "https://apiurl.com/apps/api/batch-query/", options = [Headers =[#"Content-type"="application/json", #"Authorization"="Basic <encoded username : password>"]], result = Web.Contents(actualUrl, options), #"Imported JSON" = Json.Document(result,1252) in #"Imported JSON"
I would be interested in your opinion on this vs your original suggestion? or maybe some insight on how this works.
In addition I need to make this a POST Request, in reading it sounds like I just need to add a [Content=Text.ToBinary(PostContents)])
Where PostContents = JSON Text, can you provide any insight on how I would add the Post Content into my request?
The easiest way to know why the authentication didn't work is by using Fiddler to compare the requests made when you used the OOTB basic authentication vs. your workaround. The built-in basic auth should create this header for you and attach it to every request.
Making Post requests in Power BI Desktop to APIs is not supported at the moment (if you use the Content option as you mentioned, you'll get a "Method Not Allowed" error). We are working on some Power BI Desktop extensibility capabilities that would enable you to do things like that and more. There is no exact ETA at the moment, but we are shooting for the first half of 2017.
Here is a POST request I used for dropbox API call
data = [ path= "/code",
header = [ #"Authorization"="Bearer ZZZZZZZZZZZ",
response = Web.Contents("https://api.dropboxapi.com/2/files/list_folder",[Content=Json.FromValue(data),Headers=header]),
out = Json.Document(response,1252)
The approach that @Youssef was mentioning also should have worked, but I know that usualy this implies that some portions of your authentication is sent over to the service adrress in plain text, and your service might have restrictions on that. Another possibility is that your service's hashing algorithm for usernameassword might differe from that of Power BI.
By the way, I had problems making POST request via Web.Contents only when using Active Directroy. As long as you include some sort of authenticated token in the Header of your request, you should be fine.