Adding passwordCredential when creating servicePrincipals is not supported. Use the addPassword method to add passwords or secrets for a servicePrincipal.
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
For multitenant apps, the calling user must also be in one of the following Microsoft Entra roles:
Global Administrator
Application Administrator
Cloud Application Administrator roles
For single-tenant apps where the calling user is a nonadmin user but is the owner of the backing application, the user must have the Application Developer role.
HTTP request
PATCH /servicePrincipals(appId='appId')
Request headers
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
Prefer
create-if-missing. Required for upsert behavior, otherwise the request is treated as an update operation.
Request body
In the request body, supply a JSON representation of a servicePrincipal object.
Response
If successful, if a servicePrincipal with appId doesn't exist, this method returns a 201 Created response code and a new servicePrincipal object in the response body.
If a servicePrincipal with appId already exists, this method updates the servicePrincipal object and returns a 204 No Content response code.
Examples
Example 1: Create a new servicePrincipal if it doesn't exist
The following example creates a servicePrincipal because a servicePrincipal with the specified appId value doesn't exist.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new ServicePrincipal
{
DisplayName = "My app instance",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.ServicePrincipalsWithAppId("{appId}").PatchAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.Headers.Add("Prefer", "create-if-missing");
});
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc service-principals-with-app-id patch --app-id {app-id} --body '{\
"displayName": "My app instance"\
}\
'
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
ServicePrincipal servicePrincipal = new ServicePrincipal();
servicePrincipal.setDisplayName("My app instance");
ServicePrincipal result = graphClient.servicePrincipalsWithAppId("{appId}").patch(servicePrincipal, requestConfiguration -> {
requestConfiguration.headers.add("Prefer", "create-if-missing");
});
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new ServicePrincipal
{
DisplayName = "My app instance",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.ServicePrincipalsWithAppId("{appId}").PatchAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.Headers.Add("Prefer", "create-if-missing");
});
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc service-principals-with-app-id patch --app-id {app-id} --body '{\
"displayName": "My app instance"\
}\
'
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
ServicePrincipal servicePrincipal = new ServicePrincipal();
servicePrincipal.setDisplayName("My app instance");
ServicePrincipal result = graphClient.servicePrincipalsWithAppId("{appId}").patch(servicePrincipal, requestConfiguration -> {
requestConfiguration.headers.add("Prefer", "create-if-missing");
});
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź: https://aka.ms/ContentUserFeedback.