Forum Discussion

bato93's avatar
bato93
New Member
2 years ago

Adding Entra User Group to Power BI Datasource [C# / Power BI SDK]

Hi everyone,

 

I am using the Power BI SDK to manage my Power BI environment. I came across a issue that seems impossible to solve, when managing the Datasource through app.powerbi.com I can add a User Group from Entra ID to the connection that I setup but when I try adding a user group using the object id in Entra I get a BadRequest.

 

I have followed the documentation and tried every possible combination but I always receive BadRequest, the funny part is if I try adding a user email that works. Below are the exmples that I tried:

 

This one works when adding a email user:

 

 

public Task AddDataSourceUserEmail(Gateway gateway, GatewayDatasource datasource, string email)
{
    return _powerBiClient.Gateways.AddDatasourceUserAsync(gateway.Id, datasource.Id, new DatasourceUser()
    {
        EmailAddress = email,
        DatasourceAccessRight = DatasourceUserAccessRight.Read
    });
}

 

 

 

This is what I got from Network when adding a "Group" to the Datasource through app.powerbi.com which works:

 

So I tried copying the same format when submitting through Power BI SDK (same object id as above is passed as the identifier):

 

 

public Task AddDataSourceUserIdentifier(Gateway gateway, GatewayDatasource datasource, string identifier)
{
    return _powerBiClient.Gateways.AddDatasourceUserWithHttpMessagesAsync(gateway.Id, datasource.Id,
                   new DatasourceUser()
                   {
                       PrincipalType = PrincipalType.User,
                       Identifier = identifier,
                       DatasourceAccessRight = DatasourceUserAccessRight.Read
                   });
}

 

 

 

I also tried using:

PrincipalType.Group and PrincipalType.App but none of them work I always get BadRequest with this message in the header:

DMTS_PrincipalsAreInvalidError

 

I also tried passing the object id as the Email Address in DataSourceUser but every time the same result.

 

 

Steps to reproduce the error:

1) Create a connection in Power BI

2) Create a user group in Azure Entra ID

3) Try adding the user group to the connection using the Power BI SDK function AddDatasourceUserWithHttpMessagesAsync

 

If you do Step 1 and 2 and manually add the user group to the connection through app.powerbi.com it works

 

Would appreciate any guidance I have already lost days trying to figure it out

2 Replies