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.
Permission type
Least privileged permissions
Higher privileged permissions
Delegated (work or school account)
User.ReadWrite.All
Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Not supported.
Application
User.ReadWrite.All
Directory.ReadWrite.All
For delegated scenarios, the calling user needs at least one of the following Microsoft Entra roles.
Directory Writers
License Administrator
User Administrator
HTTP request
POST /users/{id | userPrincipalName}/assignLicense
A collection of assignedLicense objects that specify the licenses to add. You can disable plans associated with a license by setting the disabledPlans property on an assignedLicense object.
removeLicenses
Guid collection
A collection of GUIDs that identify the licenses to remove.
Response
If successful, this method returns 200 OK response code and user object in the response body.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Me.AssignLicense;
using Microsoft.Graph.Models;
var requestBody = new AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
new AssignedLicense
{
DisabledPlans = new List<Guid?>
{
Guid.Parse("11b0131d-43c8-4bbb-b2c8-e80f9a50834a"),
},
SkuId = Guid.Parse("45715bb8-13f9-4bf6-927f-ef96c102d394"),
},
},
RemoveLicenses = new List<Guid?>
{
Guid.Parse("bea13e0c-3828-4daa-a392-28af7ff61a0f"),
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.AssignLicense.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.users.item.assignlicense.AssignLicensePostRequestBody assignLicensePostRequestBody = new com.microsoft.graph.users.item.assignlicense.AssignLicensePostRequestBody();
LinkedList<AssignedLicense> addLicenses = new LinkedList<AssignedLicense>();
AssignedLicense assignedLicense = new AssignedLicense();
LinkedList<UUID> disabledPlans = new LinkedList<UUID>();
disabledPlans.add(UUID.fromString("11b0131d-43c8-4bbb-b2c8-e80f9a50834a"));
assignedLicense.setDisabledPlans(disabledPlans);
assignedLicense.setSkuId(UUID.fromString("45715bb8-13f9-4bf6-927f-ef96c102d394"));
addLicenses.add(assignedLicense);
assignLicensePostRequestBody.setAddLicenses(addLicenses);
LinkedList<UUID> removeLicenses = new LinkedList<UUID>();
removeLicenses.add(UUID.fromString("bea13e0c-3828-4daa-a392-28af7ff61a0f"));
assignLicensePostRequestBody.setRemoveLicenses(removeLicenses);
var result = graphClient.me().assignLicense().post(assignLicensePostRequestBody);
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedere https://aka.ms/ContentUserFeedback.