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 one of the following Microsoft Entra roles.
Directory Writers
License Administrator
User Administrator
Global Administrator
HTTP request
POST /users/{id | userPrincipalName}/assignLicense
Request headers
Header
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, provide a JSON object with the following parameters.
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);
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignLicensePostRequestBody();
$addLicensesAssignedLicense1 = new AssignedLicense();
$addLicensesAssignedLicense1->setDisabledPlans(['11b0131d-43c8-4bbb-b2c8-e80f9a50834a', ]);
$addLicensesAssignedLicense1->setSkuId('45715bb8-13f9-4bf6-927f-ef96c102d394');
$addLicensesArray []= $addLicensesAssignedLicense1;
$requestBody->setAddLicenses($addLicensesArray);
$requestBody->setRemoveLicenses(['bea13e0c-3828-4daa-a392-28af7ff61a0f', ]);
$result = $graphServiceClient->me()->assignLicense()->post($requestBody)->wait();