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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Signon Troubles UriFormatException: Invalid URI: The hostname could not be parsed

Found some discussion but was all on Wepapp.

In a simple console app I would like to conect the PBI API, but i'm keep running into this error.

UriFormatException: Invalid URI: The hostname could not be parsed.

This is the very basic code ...

        private static string clientId = "Key-received-by-creating-the-app-with-pbi-portal";
        private static string ResourceUrl = @"https://analysis.windows.net/powerbi/api";
        private static string AuthorityUrl = @"https://login.windows.net/common/oauth2/authorize";
        private static string ApiUrl = @"https://api.powerbi.com/";
        private static string token;
        private static PowerBIClient pbiClient;

        static void Main(string[] args)
        {
            Console.WriteLine("Connecting ...");
            pbiClient = GetToken();
            Console.WriteLine("Conneced.");
            Console.ReadKey();
        }

        private static PowerBIClient GetToken()
        {
            var credential = new UserPasswordCredential("a.user@somedomain.be", "xyz");
            var authenticationContext = new AuthenticationContext(AuthorityUrl, false);
            var authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, clientId, credential).Result;
            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials);

            return client;
        }

If somebody could give me a hand, i'm not a C# developper, but would like to create a simple program to define py push datasets.

 

Kind regards, Harry

0 REPLIES 0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.