skip to Main Content

I want to retrieve the service principal object given an application ID.

The .NET SDK provides the following endpoint for that:

GET /servicePrincipals(appId='{appId}')

However, I don’t see how to call that endpoint, only the one with the service principal’s object ID:

await graphClient.ServicePrincipals[applicationId].PatchAsync(new ServicePrincipal
{
   AccountEnabled = false
}, cancellationToken: cancellationToken);

Any ideas?

https://learn.microsoft.com/en-us/graph/api/serviceprincipal-get?view=graph-rest-1.0&tabs=csharp

Furthermore, would it be possible to disable the service principal in a single call, instead of two, given the application ID?

2

Answers


  1. I have called the below API using Graph Exporer and it give me the serviceprincial object for a specific application id.

    https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '870c4f2e-85b6-4d43-bdda-6ed9a579b725'
    

    enter image description here

    We can fetch the serviceprincipal object of the specific application id using OData filter query parameter in C# as below.

    var result = await graphClient.ServicePrincipals.GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Filter = "appId eq '870c4f2e-85b6-4d43-bdda-6ed9a579b725'";
        requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
    });
    
    Login or Signup to reply.
  2. The SDK should have the method ServicePrincipalsWithAppId

    var result = await graphClient.ServicePrincipalsWithAppId("{appId}").GetAsync();
    

    The PATCH is also possible

    await graphClient.ServicePrincipalsWithAppId(applicationId).PatchAsync(new ServicePrincipal
    {
       AccountEnabled = false
    }, cancellationToken: cancellationToken);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search