Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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-...
(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?
Solved! Go to Solution.
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 ?
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("UserName@MyTenent.onMicrosoft.com", "myEasyToCrackPassword"); var userAuthnResult = authenticationContext.AcquireTokenAsync(ProgramConstants.PowerBiServiceResourceUri, ProgramConstants.ClientID, userCreds).Result;
Update your username and password in the userpasswordcredentials
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 303
Exceçã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:02Z
Exceção interna 2:
AdalServiceException: Response status code does not indicate success: 400 (BadRequest).
What should be?
BEST regards
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("UserName@MyTenent.onMicrosoft.com", "myEasyToCrackPassword"); var userAuthnResult = authenticationContext.AcquireTokenAsync(ProgramConstants.PowerBiServiceResourceUri, ProgramConstants.ClientID, userCreds).Result;
@Jayendran Thank you for the help. I really appreciate it.
It worked to authenticate but now I´m facing one problem in my workspace. I already set all the permissions to this app, including read/write workspaces.
Any tip? I´m trying everything in Azure and nothing solve this problem.?
Warm Regards.
Hi @brunozanoelo ,
I tried the same thing it works for me.
Here some few tips
I see that this is calling
https://api.powerbi.com/v1.0/myorg/groups
https://docs.microsoft.com/en-us/rest/api/power-bi/groups/getgroups
It requires the scope of Workspace.Read.All or Workspace.ReadWrite.All but from the screenshot you also having that
Hello my friend,
I´ve found that the problem is actually not in the workspace, but still in the authentication function.
See the image bellow. I think my code is correct, isn't? The client ID it´s the correct one, I already checked!
Yes pls use the fiddler to find what was the failure from the API. Since it's not reproduce from my side. Fiddler will get the exact issue here
But in the app, the errorstill persist.
Previously you said that autentication is not passed which means it should have a 200 status code. In such scenario you should see the error in fiddler.
However you said that fiddler is successful. It doesn't make sense !
However, Can you change your code to like the below
HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken); client.DefaultRequestHeaders.Add("Accept", "application/json"); HttpResponseMessage response = client.GetAsync(restUri).Result; var content = response.Content.ReadAsStringAsync().Result; Console.WriteLine(content);
this way you can get what is the result of the API.
I believe I'm getting an sucessfully authentication, since I get the IDToken from the
Console.WriteLine(userAuthnResult.IdToken);
The consolewriteline result an empty string, BUT, take a look of this message when I debug... When the application uses the Workspace function, I get the status code 403 - Forbidden.
I´m logging in with my PowerBI PRO account, I don´t have any embedded capacity in Azure portal, I need to create it and change my workspace to "dedicated capacity"? https://community.powerbi.com/t5/Service/PowerBI-Embedded-Service-403/td-p/71382
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 ?
Got it! I´ve found the problem!
I will post this source in github in a few days. I just need to fix a few details. (I think this will help a lot of ppl too) 🙂
I´m facing one problem that when I send my dataset, he doesn't replace, even if is the same pbix name, there´s any possibility to replace the dataset? I need this because I have tons of configurations to auto refresh data.
Thank you a lot my friend.
Warm Regards,
Looking forward to see how you solved this, please post the solution on github and share here. Thank you !
Glad you solved your problem.
Yes there is way to replace the dataset, using the ImportConflictHandlerMode by assigning CreateOrOverwrite
https://api.powerbi.com/v1.0/myorg/imports?datasetDisplayName={datasetDisplayName}&nameConflict={nameConflict}
Reference:
https://docs.microsoft.com/en-us/rest/api/power-bi/imports/postimport#importconflicthandlermode
@Jayendran , there´s no property in the dataset object to use the dataset/refresh history;
https://powerbi.microsoft.com/en-us/blog/announcing-data-refresh-apis-in-the-power-bi-service/
I´m trying to implement this, will keep in touch...
User | Count |
---|---|
18 | |
11 | |
5 | |
4 | |
3 |