Add or remove licenses for the user to enable or disable their use of Microsoft cloud offerings that the company has licenses to. For example, an organization can have a Microsoft 365 Enterprise E3 subscription with 100 licenses, and this request assigns one of those licenses to a specific user. You can also enable and disable specific plans associated with a subscription.
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)
LicenseAssignment.ReadWrite.All
Directory.ReadWrite.All, User.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Not supported.
Application
LicenseAssignment.ReadWrite.All
Directory.ReadWrite.All, User.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 servicePlans associated with a license by setting the disabledPlans property on an assignedLicense object.
removeLicenses
Guid collection
A collection of skuIds that identify the licenses to remove. Required.
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);