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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Adding service principal (App registrations) to to data source users

Hi! I am using REST API to add service principal (App registrations) to to data source users.  (documentaion: https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/add-datasource-user)For autentication I am using AccessToken generated for PowerBI Service principals with granted permission: 

gryczanu_0-1648206920156.png

Here is a PowerShell code which I use to add Service Princpal to datasoource users

 

$Headers = @{Authorization = "Bearer $AccessToken"}
$Uri = "https://api.powerbi.com/v1.0/myorg/gateways/$GatewayId/datasources/$DatasourceId/users"

$Body = @{
    identifier = $AdObjectIdentifier
    principalType = "App"
    datasourceAccessRight = "Read"
    displayName = "$SPN"
}
 
Invoke-RestMethod -Uri $Uri -Headers $Headers -Method Post -ContentType "application/json" -Body (ConvertTo-Json $Body)
 
I get error: 
{"error":{"code":"ADGraphEntityOperationFailedResourceNotFound","pbi.error":{"code":"ADGraphEntityOperationFailedResourceNotFound","parameters":{},"details":[],"exceptionCulprit":1}}}
 
Do you have any suggestion why it doesn't wokr? 
Thanks for your help!
  
4 REPLIES 4
Anonymous
Not applicable

@V-lianl-msft  I have checked all parameter. They are correct. Do you have any advise what can I chcek else?

Anonymous
Not applicable

No, it doesn't. I can't add manually service principal to datasource users on GUI. 

It wokrs when I use PowerShell 7 with  DataGateway module (Install-Module -Name DataGateway, require PowerShell higher than 6.2.2) and  when I run connect commands: Connect-PowerBIServiceAccount and Login-DataGatewayServiceAccount  (tested by using user account, not as a service prinipal - app registration). Do we have any solution for PowerShell 5.1? Is it necessary to authenticate by uisng  Login-DataGatewayServiceAccount ?

Hi @Anonymous ,

 

Please check if you have given the appropriate values for the parameters applied in command:

-GatewayClusterId

-GatewayClusterDatasourceId

-Identifier : provide the object id of service principal

 

You can also refer to this video:

https://www.youtube.com/watch?v=lfP6ygindSU 


Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

does it work when you do that in the gateway management center webpage?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.