user: assignLicense
Article
03/02/2023
10 contributors
Feedback
In this article
Namespace: microsoft.graph
Add or remove subscriptions for the user. You can also enable and disable specific plans associated with a subscription.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
User.ReadWrite.All, Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
User.ReadWrite.All, Directory.ReadWrite.All
HTTP request
POST /users/{id | userPrincipalName}/assignLicense
Header
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, provide a JSON object with the following parameters.
Parameter
Type
Description
addLicenses
assignedLicense collection
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.
Example
Here is an example of how to call this API.
Request
Here is an example of the request.
POST https://graph.microsoft.com/v1.0/me/assignLicense
Content-type: application/json
{
"addLicenses": [
{
"disabledPlans": [ "11b0131d-43c8-4bbb-b2c8-e80f9a50834a" ],
"skuId": "45715bb8-13f9-4bf6-927f-ef96c102d394"
}
],
"removeLicenses": [ "bea13e0c-3828-4daa-a392-28af7ff61a0f" ]
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Me.AssignLicense.AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
new AssignedLicense
{
DisabledPlans = new List<11b0131d-43c8-4bbb-b2c8-e80f9a50834a>
{
Guid.Parse("11b0131d-43c8-4bbb-b2c8-e80f9a50834a"),
},
SkuId = Guid.Parse("45715bb8-13f9-4bf6-927f-ef96c102d394"),
},
},
RemoveLicenses = new List<Bea13e0c-3828-4daa-a392-28af7ff61a0f>
{
Guid.Parse("bea13e0c-3828-4daa-a392-28af7ff61a0f"),
},
};
var result = await graphClient.Me.AssignLicense.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const user = {
addLicenses: [
{
disabledPlans: [ '11b0131d-43c8-4bbb-b2c8-e80f9a50834a' ],
skuId: '45715bb8-13f9-4bf6-927f-ef96c102d394'
}
],
removeLicenses: [ 'bea13e0c-3828-4daa-a392-28af7ff61a0f' ]
};
await client.api('/me/assignLicense')
.post(user);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<AssignedLicense> addLicensesList = new LinkedList<AssignedLicense>();
AssignedLicense addLicenses = new AssignedLicense();
LinkedList<UUID> disabledPlansList = new LinkedList<UUID>();
disabledPlansList.add(UUID.fromString("11b0131d-43c8-4bbb-b2c8-e80f9a50834a"));
addLicenses.disabledPlans = disabledPlansList;
addLicenses.skuId = UUID.fromString("45715bb8-13f9-4bf6-927f-ef96c102d394");
addLicensesList.add(addLicenses);
LinkedList<UUID> removeLicensesList = new LinkedList<UUID>();
removeLicensesList.add(UUID.fromString("bea13e0c-3828-4daa-a392-28af7ff61a0f"));
graphClient.me()
.assignLicense(UserAssignLicenseParameterSet
.newBuilder()
.withAddLicenses(addLicensesList)
.withRemoveLicenses(removeLicensesList)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphusers "github.com/microsoftgraph/msgraph-sdk-go/users"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient, err := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphusers.NewAssignLicensePostRequestBody()
assignedLicense := graphmodels.NewAssignedLicense()
disabledPlans := []string {
:= uuid.MustParse("11b0131d-43c8-4bbb-b2c8-e80f9a50834a")
assignedLicense.Set(&)
}
assignedLicense.SetDisabledPlans(disabledPlans)
skuId := uuid.MustParse("45715bb8-13f9-4bf6-927f-ef96c102d394")
assignedLicense.SetSkuId(&skuId)
addLicenses := []graphusers.AssignedLicenseable {
assignedLicense,
}
requestBody.SetAddLicenses(addLicenses)
removeLicenses := []string {
:= uuid.MustParse("bea13e0c-3828-4daa-a392-28af7ff61a0f")
requestBody.Set(&)
}
requestBody.SetRemoveLicenses(removeLicenses)
result, err := graphClient.Me().AssignLicense().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Users.Actions
$params = @{
addLicenses = @(
@{
disabledPlans = @(
"11b0131d-43c8-4bbb-b2c8-e80f9a50834a"
)
skuId = "45715bb8-13f9-4bf6-927f-ef96c102d394"
}
)
removeLicenses = @(
"bea13e0c-3828-4daa-a392-28af7ff61a0f"
)
}
# A UPN can also be used as -UserId.
Set-MgUserLicense -UserId $userId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
Here is an example of the response. Note: The response object shown here might be shortened for readability.
HTTP/1.1 200 OK
Content-type: application/json
{
"accountEnabled": true,
"assignedLicenses": [
{
"disabledPlans": [ "11b0131d-43c8-4bbb-b2c8-e80f9a50834a" ],
"skuId": "0118A350-71FC-4EC3-8F0C-6A1CB8867561"
}
],
"assignedPlans": [
{
"assignedDateTime": "2016-10-02T12:13:14Z",
"capabilityStatus": "capabilityStatus-value",
"service": "service-value",
"servicePlanId": "bea13e0c-3828-4daa-a392-28af7ff61a0f"
}
],
"businessPhones": [
"businessPhones-value"
],
"city": "city-value",
"companyName": "companyName-value"
}