User Profile
NickSandel
Frequent Visitor
Joined 3 years ago
User Widgets
Contributions
Re: How can I get a service principal user to publish a report with a connection to a service datasource
I managed to get this working eventually. It was by querying the API directly without the PowerBI cmdlets and it required a service principal, a user on that service principal with MFA turned off, both were admins on the workspace and then the access token used to import the report had to be created under that user and service principal. Very awkward, no documentation hints this is what's actually needed and we largely got there through trial and error.329Views0likes0CommentsHow can I get a service principal user to publish a report with a connection to a service datasource
I have a powershell script which: 1) Connects to the power bi service with a service principal account: $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationID, $SecurePassword Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $TenantID 2) Loads a local pbix file which has a connection to the power bi service like: "server=powerbi://api.powerbi.com/v1.0/myorg/" + $workspacename + ";database=" + $Dataset 3) Publishes the pbix report with code like: New-PowerBIReport -Path $fullfilepath -Name $reportname -Workspace $workspace -ConflictAction CreateOrOverwrite -Verbose This hits a 401 Unauthorized error. The full stack from using Resolve-PowerBIError is: Message : Operation returned an invalid status code 'Unauthorized' StackTrace : at Microsoft.PowerBI.Api.V2.Imports.UploadFile(String groupId, Stream file, String datasetDisplayName, String nameConflict, Nullable`1 skipReport, Dictionary`2 customHeaders, CancellationToken cancellationToken) at Microsoft.PowerBI.Api.V2.Imports.PostImportFileWithHttpMessage(String groupId, Stream file, String datasetDisplayName, String nameConflict, Nullable`1 skipReport, Dictionary`2 customHeaders, CancellationToken cancellationToken) at Microsoft.PowerBI.Api.V2.ImportsExtensions.PostImportWithFileInGroup(IImports operations, String groupId, Stream fileStream, String datasetDisplayName, String nameConflict, Nullable`1 skipReport) at Microsoft.PowerBI.Common.Api.Reports.ReportsClient.PostImportForWorkspace(Guid workspaceId, String datasetDisplayName, String filePath, ImportConflictHandlerModeEnum nameConflict) at Microsoft.PowerBI.Common.Api.Reports.ReportsClient.PostReportForWorkspace(Guid workspaceId, String reportName, String filePath, ImportConflictHandlerModeEnum nameConflict, Int32 timeout) at Microsoft.PowerBI.Commands.Reports.NewPowerBIReport.ExecuteCmdlet() at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.ProcessRecord() If I authenticate as myself instead of the service principal with just (Connect-PowerBIServiceAccount) then the code all works fine. If I have a datasource connection in my pbix to a local SSAS server it will create the report - it doesn't work with a connection like this but it proves the service principal CAN create reports. We have checked settings like: service principal is admin in workspace, it has what looks like the right permissions in API permissions (most posts I find say it doesn't need these if the PBI admin portal settings are right which they are). I tried the steps in this 2 part post: https://www.dataunlock.com.au/power-bi-rest-api-using-service-principal-part-1/ but it's still stuck. It really seems like it can publish the report but it fails on validating the connection as the service principal wheras under my AD account it will happily validate this connection. Is there something I can do in setting the PBIX connection string to enable this to work?399Views0likes1CommentRe: Publishing and refreshing report with service principal
Has someone got an example of how to use this with the cmdlet New-PowerBIReport? I have been trying and keep hitting a 401 Unauthorized error. By chance one time I published some different pbix reports which worked fine but I think they had a connection to a local dataset. When I change the connection to a dataset in the workspace with syntax like: "server=powerbi://api.powerbi.com/v1.0/myorg/WORKSPACE;database=Model" Then it fails. The cmdlet works fine with my credentials. I tried adding ";User ID=app:appid@tenantid;Password=password" but that hits a 500 error instead2.4KViews0likes0Comments
Data Privacy
Microsoft Fabric Community and Privacy
To learn more about how we manage your data, please review the Microsoft Fabric Community Data Privacy guide.