Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

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: 

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

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

  • Anonymous's avatar
    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 ?

    • V-lianl-msft's avatar
      V-lianl-msft
      Icon for Community Support rankCommunity Support

      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.

  • Anonymous's avatar
    Anonymous
    Not applicable

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