Forum Discussion
Uploading PBIX File in C# sample (HELP!)
Good morning everyone,
For centuries I'm looking to upload pbix files automatically in my workspace locate into the PowerBI Service. I
The best example is this one: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/Publishing-PBIX-Files-with-the-Power-BI-REST-API/td-p/153034
(This video demonstrates developing a C# console to automate uploading and publishing PBIX project files created with Power BI Desktop to PowerBI.com.)
I´ve found this article that explains how the C# works BUT when i select "Native App" it doesn't appear the "Redirect URL". The problem is that when I run the C# sample application , it requires the redirect URL.
There´s anyone here that knows about C# and can help me?
Hi brunozanoelo
You don't need dedicated capacity now. It has no connection with the autentication.
Are you running behind the code behind any proxy ? Which blocks your autentication ?
Can you try executing in Post man ?
15 Replies
- JayendranSolution Sage
Hi brunozanoelo
You don't really need redirect url for a native app. All you need to use the usercredential approach which is commented on the code you need to uncomment that. Because powerbi no longer support the client id with out Azure AD registration.
// create new ADAL authentication context var authenticationContext = new AuthenticationContext(ProgramConstants.AzureAuthorizationEndpoint); //use authentication context to trigger user login and then acquire access token //var userAuthnResult = // authenticationContext.AcquireTokenAsync(ProgramConstants.PowerBiServiceResourceUri, // ProgramConstants.ClientID, // new Uri(ProgramConstants.RedirectUri), // new PlatformParameters(PromptBehavior.Auto)).Result; // use authentication context to trigger user sign-in and return access token var userCreds = new UserPasswordCredential("[email protected]", "myEasyToCrackPassword"); var userAuthnResult = authenticationContext.AcquireTokenAsync(ProgramConstants.PowerBiServiceResourceUri, ProgramConstants.ClientID, userCreds).Result;Update your username and password in the userpasswordcredentials
- brunozanoeloPost Patron
Thank you so much for your reply.
I´ve changed my code as u said but now is giving me this error:System.AggregateException
HResult=0x80131500
Message=Um ou mais erros.
Source=mscorlib
StackTrace:
em System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
em System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
em System.Threading.Tasks.Task`1.get_Result()
em PbixInstallerForPowerBI.Program.AcquireAccessToken() em D:\Bitbucket\PowerBI\Integração REST\PbixInstallerForPowerBI-master\PbixInstallerForPowerBI\Program.cs:linha 54
em PbixInstallerForPowerBI.Program.Main() em D:\Bitbucket\PowerBI\Integração REST\PbixInstallerForPowerBI-master\PbixInstallerForPowerBI\Program.cs:linha 303Exceção interna 1:
AdalServiceException: AADSTS65001: The user or administrator has not consented to use the application with ID '75d071b1-378d-4f76-bb68-da4e033cf646' named 'instalador'. Send an interactive authorization request for this user and resource.
Trace ID: 20ec587e-39c6-4afa-acbb-67dfe8c9c800
Correlation ID: a7f7e02e-ffde-453b-b331-89c2e89a3601
Timestamp: 2019-08-14 17:32:02ZExceção interna 2:
AdalServiceException: Response status code does not indicate success: 400 (BadRequest).
What should be?
BEST regards- JayendranSolution Sage
Hi brunozanoelo
The admin needs to consent your application. You can do this from you Azure Active Directory for your application called instalador
Another little change in the code to force TLS1.2, pls update your code like below
System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12; var userCreds = new UserPasswordCredential("[email protected]", "myEasyToCrackPassword"); var userAuthnResult = authenticationContext.AcquireTokenAsync(ProgramConstants.PowerBiServiceResourceUri, ProgramConstants.ClientID, userCreds).Result;