APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Add or remove licenses for the user to enable or disable their use of Microsoft cloud offerings. 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. To learn more about subscriptions and licenses, see this Technet article.
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.
Response
If successful, this method returns 200 OK response code and an updated user object in the response body.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Beta.Me.AssignLicense.AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
new AssignedLicense
{
DisabledPlans = new List<8a256a2b-b617-496d-b51b-e76466e88db0>
{
Guid.Parse("8a256a2b-b617-496d-b51b-e76466e88db0"),
},
SkuId = Guid.Parse("84a661c4-e949-4bd2-a560-ed7766fcaf2b"),
},
new AssignedLicense
{
DisabledPlans = new List<String>
{
},
SkuId = Guid.Parse("f30db892-07e9-47e9-837c-80727f46fd3d"),
},
},
RemoveLicenses = new List<String>
{
},
};
var result = await graphClient.Me.AssignLicense.PostAsync(requestBody);
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
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("8a256a2b-b617-496d-b51b-e76466e88db0"));
addLicenses.disabledPlans = disabledPlansList;
addLicenses.skuId = UUID.fromString("84a661c4-e949-4bd2-a560-ed7766fcaf2b");
addLicensesList.add(addLicenses);
AssignedLicense addLicenses1 = new AssignedLicense();
LinkedList<UUID> disabledPlansList1 = new LinkedList<UUID>();
addLicenses1.disabledPlans = disabledPlansList1;
addLicenses1.skuId = UUID.fromString("f30db892-07e9-47e9-837c-80727f46fd3d");
addLicensesList.add(addLicenses1);
LinkedList<UUID> removeLicensesList = new LinkedList<UUID>();
graphClient.me()
.assignLicense(UserAssignLicenseParameterSet
.newBuilder()
.withAddLicenses(addLicensesList)
.withRemoveLicenses(removeLicensesList)
.build())
.buildRequest()
.post();
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Import-Module Microsoft.Graph.Users.Actions
$params = @{
addLicenses = @(
@{
disabledPlans = @(
"8a256a2b-b617-496d-b51b-e76466e88db0"
)
skuId = "84a661c4-e949-4bd2-a560-ed7766fcaf2b"
}
@{
disabledPlans = @(
)
skuId = "f30db892-07e9-47e9-837c-80727f46fd3d"
}
)
removeLicenses = @(
)
}
# A UPN can also be used as -UserId.
Set-MgUserLicense -UserId $userId -BodyParameter $params
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Beta.Me.AssignLicense.AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
},
RemoveLicenses = new List<F30db892-07e9-47e9-837c-80727f46fd3d>
{
Guid.Parse("f30db892-07e9-47e9-837c-80727f46fd3d"),
Guid.Parse("84a661c4-e949-4bd2-a560-ed7766fcaf2b"),
},
};
var result = await graphClient.Me.AssignLicense.PostAsync(requestBody);
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.
Import-Module Microsoft.Graph.Users.Actions
$params = @{
addLicenses = @(
)
removeLicenses = @(
"f30db892-07e9-47e9-837c-80727f46fd3d"
"84a661c4-e949-4bd2-a560-ed7766fcaf2b"
)
}
# A UPN can also be used as -UserId.
Set-MgUserLicense -UserId $userId -BodyParameter $params
Important
Microsoft Graph SDKs use the v1.0 version of the API by default, and do not support all the types, properties, and APIs available in the beta version. For details about accessing the beta API with the SDK, see Use the Microsoft Graph SDKs with the beta API.