Espacio de nombres: microsoft.graph
Agregar o quitar licencias en un grupo. Las licencias asignadas al grupo se asignarán a todos los usuarios del grupo. Las licencias basadas en grupos son una alternativa a las licencias directas de usuarios. Para obtener más información sobre las licencias basadas en grupos, consulte ¿Qué es las licencias basadas en grupos en Microsoft Entra ID?
Para obtener las suscripciones disponibles en el directorio, realice una solicitud GET subscribedSkus.
Esta API está disponible en las siguientes implementaciones nacionales de nube.
| Servicio global |
Gobierno de EE. UU. L4 |
Us Government L5 (DOD) |
China operada por 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Permissions
Elija el permiso o los permisos marcados como con privilegios mínimos para esta API. Use un permiso o permisos con privilegios superiores solo si la aplicación lo requiere. Para obtener más información sobre los permisos delegados y de aplicación, consulte Tipos de permisos. Para obtener más información sobre estos permisos, consulte la referencia de permisos.
| Tipo de permiso |
Permisos con privilegios mínimos |
Permisos con privilegios más altos |
| Delegado (cuenta profesional o educativa) |
LicenseAssignment.ReadWrite.All |
Directory.ReadWrite.All, Group.ReadWrite.All |
| Delegado (cuenta personal de Microsoft) |
No admitida. |
No admitida. |
| Aplicación |
LicenseAssignment.ReadWrite.All |
Directory.ReadWrite.All, Group.ReadWrite.All |
Importante
En escenarios delegados con cuentas profesionales o educativas, al usuario que ha iniciado sesión se le debe asignar un rol de Microsoft Entra compatible o un rol personalizado con el permiso de microsoft.directory/groups/assignLicense rol. Se admiten los siguientes roles con privilegios mínimos para esta operación:
- Escritores de directorios
- Administrador de grupos
- Administrador de licencias
- Administrador de usuarios
Solicitud HTTP
POST /groups/{id}/assignLicense
| Encabezado |
Valor |
| Authorization |
{token} de portador. Obligatorio. Obtenga más información sobre la autenticación y la autorización. |
| Content-Type |
application/json. Obligatorio. |
Cuerpo de la solicitud
En el cuerpo de la solicitud, proporcione un objeto JSON con los siguientes parámetros.
| Parámetro |
Tipo |
Descripción |
| addLicenses |
Colección assignedLicense |
Colección de objetos assignedLicense que especifican las licencias que se van a agregar. Puede deshabilitar servicePlans asociado a una licencia estableciendo la propiedad disabledPlans en un objeto assignedLicense . |
| removeLicenses |
Colección Guid |
Colección de skuIds que identifican las licencias que se van a quitar. Obligatorio. Puede ser una colección vacía. |
Respuesta
Si se ejecuta correctamente, este método devuelve un 202 Accepted código de respuesta y un objeto de grupo de destino en el cuerpo de la respuesta.
Ejemplos
Ejemplo 1: Agregar licencias al grupo
En el ejemplo siguiente se agregan licencias al grupo.
Solicitud
POST https://graph.microsoft.com/v1.0/groups/1132b215-826f-42a9-8cfe-1643d19d17fd/assignLicense
Content-type: application/json
{
"addLicenses": [
{
"disabledPlans": [
"113feb6c-3fe4-4440-bddc-54d774bf0318",
"14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"
],
"skuId": "b05e124f-c7cc-45a0-a6aa-8cf78c946968"
},
{
"disabledPlans": [
"a413a9ff-720c-4822-98ef-2f37c2a21f4c"
],
"skuId": "c7df2760-2c81-4ef7-b578-5b5392b571df"
}
],
"removeLicenses": []
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Groups.Item.AssignLicense;
using Microsoft.Graph.Models;
var requestBody = new AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
new AssignedLicense
{
DisabledPlans = new List<Guid?>
{
Guid.Parse("113feb6c-3fe4-4440-bddc-54d774bf0318"),
Guid.Parse("14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"),
},
SkuId = Guid.Parse("b05e124f-c7cc-45a0-a6aa-8cf78c946968"),
},
new AssignedLicense
{
DisabledPlans = new List<Guid?>
{
Guid.Parse("a413a9ff-720c-4822-98ef-2f37c2a21f4c"),
},
SkuId = Guid.Parse("c7df2760-2c81-4ef7-b578-5b5392b571df"),
},
},
RemoveLicenses = new List<string>
{
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].AssignLicense.PostAsync(requestBody);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-sdk-go/groups"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphgroups.NewAssignLicensePostRequestBody()
assignedLicense := graphmodels.NewAssignedLicense()
disabledPlans := []uuid.UUID {
uuid.MustParse("113feb6c-3fe4-4440-bddc-54d774bf0318"),
uuid.MustParse("14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"),
}
assignedLicense.SetDisabledPlans(disabledPlans)
skuId := uuid.MustParse("b05e124f-c7cc-45a0-a6aa-8cf78c946968")
assignedLicense.SetSkuId(&skuId)
assignedLicense1 := graphmodels.NewAssignedLicense()
disabledPlans := []uuid.UUID {
uuid.MustParse("a413a9ff-720c-4822-98ef-2f37c2a21f4c"),
}
assignedLicense1.SetDisabledPlans(disabledPlans)
skuId := uuid.MustParse("c7df2760-2c81-4ef7-b578-5b5392b571df")
assignedLicense1.SetSkuId(&skuId)
addLicenses := []graphmodels.AssignedLicenseable {
assignedLicense,
assignedLicense1,
}
requestBody.SetAddLicenses(addLicenses)
removeLicenses := []string {
}
requestBody.SetRemoveLicenses(removeLicenses)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
assignLicense, err := graphClient.Groups().ByGroupId("group-id").AssignLicense().Post(context.Background(), requestBody, nil)
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.groups.item.assignlicense.AssignLicensePostRequestBody assignLicensePostRequestBody = new com.microsoft.graph.groups.item.assignlicense.AssignLicensePostRequestBody();
LinkedList<AssignedLicense> addLicenses = new LinkedList<AssignedLicense>();
AssignedLicense assignedLicense = new AssignedLicense();
LinkedList<UUID> disabledPlans = new LinkedList<UUID>();
disabledPlans.add(UUID.fromString("113feb6c-3fe4-4440-bddc-54d774bf0318"));
disabledPlans.add(UUID.fromString("14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"));
assignedLicense.setDisabledPlans(disabledPlans);
assignedLicense.setSkuId(UUID.fromString("b05e124f-c7cc-45a0-a6aa-8cf78c946968"));
addLicenses.add(assignedLicense);
AssignedLicense assignedLicense1 = new AssignedLicense();
LinkedList<UUID> disabledPlans1 = new LinkedList<UUID>();
disabledPlans1.add(UUID.fromString("a413a9ff-720c-4822-98ef-2f37c2a21f4c"));
assignedLicense1.setDisabledPlans(disabledPlans1);
assignedLicense1.setSkuId(UUID.fromString("c7df2760-2c81-4ef7-b578-5b5392b571df"));
addLicenses.add(assignedLicense1);
assignLicensePostRequestBody.setAddLicenses(addLicenses);
LinkedList<String> removeLicenses = new LinkedList<String>();
assignLicensePostRequestBody.setRemoveLicenses(removeLicenses);
var result = graphClient.groups().byGroupId("{group-id}").assignLicense().post(assignLicensePostRequestBody);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
const options = {
authProvider,
};
const client = Client.init(options);
const group = {
addLicenses: [
{
disabledPlans: [
'113feb6c-3fe4-4440-bddc-54d774bf0318',
'14ab5db5-e6c4-4b20-b4bc-13e36fd2227f'
],
skuId: 'b05e124f-c7cc-45a0-a6aa-8cf78c946968'
},
{
disabledPlans: [
'a413a9ff-720c-4822-98ef-2f37c2a21f4c'
],
skuId: 'c7df2760-2c81-4ef7-b578-5b5392b571df'
}
],
removeLicenses: []
};
await client.api('/groups/1132b215-826f-42a9-8cfe-1643d19d17fd/assignLicense')
.post(group);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Groups\Item\AssignLicense\AssignLicensePostRequestBody;
use Microsoft\Graph\Generated\Models\AssignedLicense;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignLicensePostRequestBody();
$addLicensesAssignedLicense1 = new AssignedLicense();
$addLicensesAssignedLicense1->setDisabledPlans(['113feb6c-3fe4-4440-bddc-54d774bf0318', '14ab5db5-e6c4-4b20-b4bc-13e36fd2227f', ]);
$addLicensesAssignedLicense1->setSkuId('b05e124f-c7cc-45a0-a6aa-8cf78c946968');
$addLicensesArray []= $addLicensesAssignedLicense1;
$addLicensesAssignedLicense2 = new AssignedLicense();
$addLicensesAssignedLicense2->setDisabledPlans(['a413a9ff-720c-4822-98ef-2f37c2a21f4c', ]);
$addLicensesAssignedLicense2->setSkuId('c7df2760-2c81-4ef7-b578-5b5392b571df');
$addLicensesArray []= $addLicensesAssignedLicense2;
$requestBody->setAddLicenses($addLicensesArray);
$requestBody->setRemoveLicenses([]);
$result = $graphServiceClient->groups()->byGroupId('group-id')->assignLicense()->post($requestBody)->wait();
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
Import-Module Microsoft.Graph.Groups
$params = @{
addLicenses = @(
@{
disabledPlans = @(
"113feb6c-3fe4-4440-bddc-54d774bf0318"
"14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"
)
skuId = "b05e124f-c7cc-45a0-a6aa-8cf78c946968"
}
@{
disabledPlans = @(
"a413a9ff-720c-4822-98ef-2f37c2a21f4c"
)
skuId = "c7df2760-2c81-4ef7-b578-5b5392b571df"
}
)
removeLicenses = @(
)
}
Set-MgGroupLicense -GroupId $groupId -BodyParameter $params
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.groups.item.assign_license.assign_license_post_request_body import AssignLicensePostRequestBody
from msgraph.generated.models.assigned_license import AssignedLicense
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AssignLicensePostRequestBody(
add_licenses = [
AssignedLicense(
disabled_plans = [
UUID("113feb6c-3fe4-4440-bddc-54d774bf0318"),
UUID("14ab5db5-e6c4-4b20-b4bc-13e36fd2227f"),
],
sku_id = UUID("b05e124f-c7cc-45a0-a6aa-8cf78c946968"),
),
AssignedLicense(
disabled_plans = [
UUID("a413a9ff-720c-4822-98ef-2f37c2a21f4c"),
],
sku_id = UUID("c7df2760-2c81-4ef7-b578-5b5392b571df"),
),
],
remove_licenses = [
],
)
result = await graph_client.groups.by_group_id('group-id').assign_license.post(request_body)
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
Respuesta
La respuesta es el objeto de grupo actualizado.
Nota: Se puede acortar el objeto de respuesta que se muestra aquí para mejorar la legibilidad.
HTTP/1.1 202 Accepted
Content-type: application/json
location: https://graph.microsoft.com/v2/e8e96c2a-d787-4eb1-98d7-9e57c965f1de/directoryObjects/1132b215-826f-42a9-8cfe-1643d19d17fd/Microsoft.DirectoryServices.Group
{
"id": "1132b215-826f-42a9-8cfe-1643d19d17fd",
"createdDateTime": "2021-03-12T11:15:03Z",
"groupTypes": [],
"securityEnabled": true
}
Ejemplo 2: Eliminación de licencias del grupo
En el ejemplo siguiente se quitan las licencias del grupo.
Solicitud
POST https://graph.microsoft.com/v1.0/groups/1132b215-826f-42a9-8cfe-1643d19d17fd/assignLicense
Content-type: application/json
{
"addLicenses": [],
"removeLicenses": [
"c7df2760-2c81-4ef7-b578-5b5392b571df",
"b05e124f-c7cc-45a0-a6aa-8cf78c946968"
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Groups.Item.AssignLicense;
using Microsoft.Graph.Models;
var requestBody = new AssignLicensePostRequestBody
{
AddLicenses = new List<AssignedLicense>
{
},
RemoveLicenses = new List<Guid?>
{
Guid.Parse("c7df2760-2c81-4ef7-b578-5b5392b571df"),
Guid.Parse("b05e124f-c7cc-45a0-a6aa-8cf78c946968"),
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].AssignLicense.PostAsync(requestBody);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-sdk-go/groups"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphgroups.NewAssignLicensePostRequestBody()
addLicenses := []graphmodels.AssignedLicenseable {
}
requestBody.SetAddLicenses(addLicenses)
removeLicenses := []uuid.UUID {
uuid.MustParse("c7df2760-2c81-4ef7-b578-5b5392b571df"),
uuid.MustParse("b05e124f-c7cc-45a0-a6aa-8cf78c946968"),
}
requestBody.SetRemoveLicenses(removeLicenses)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
assignLicense, err := graphClient.Groups().ByGroupId("group-id").AssignLicense().Post(context.Background(), requestBody, nil)
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.groups.item.assignlicense.AssignLicensePostRequestBody assignLicensePostRequestBody = new com.microsoft.graph.groups.item.assignlicense.AssignLicensePostRequestBody();
LinkedList<AssignedLicense> addLicenses = new LinkedList<AssignedLicense>();
assignLicensePostRequestBody.setAddLicenses(addLicenses);
LinkedList<UUID> removeLicenses = new LinkedList<UUID>();
removeLicenses.add(UUID.fromString("c7df2760-2c81-4ef7-b578-5b5392b571df"));
removeLicenses.add(UUID.fromString("b05e124f-c7cc-45a0-a6aa-8cf78c946968"));
assignLicensePostRequestBody.setRemoveLicenses(removeLicenses);
var result = graphClient.groups().byGroupId("{group-id}").assignLicense().post(assignLicensePostRequestBody);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
const options = {
authProvider,
};
const client = Client.init(options);
const group = {
addLicenses: [],
removeLicenses: [
'c7df2760-2c81-4ef7-b578-5b5392b571df',
'b05e124f-c7cc-45a0-a6aa-8cf78c946968'
]
};
await client.api('/groups/1132b215-826f-42a9-8cfe-1643d19d17fd/assignLicense')
.post(group);
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Groups\Item\AssignLicense\AssignLicensePostRequestBody;
use Microsoft\Graph\Generated\Models\AssignedLicense;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignLicensePostRequestBody();
$requestBody->setAddLicenses([ ]);
$requestBody->setRemoveLicenses(['c7df2760-2c81-4ef7-b578-5b5392b571df', 'b05e124f-c7cc-45a0-a6aa-8cf78c946968', ]);
$result = $graphServiceClient->groups()->byGroupId('group-id')->assignLicense()->post($requestBody)->wait();
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
Import-Module Microsoft.Graph.Groups
$params = @{
addLicenses = @(
)
removeLicenses = @(
"c7df2760-2c81-4ef7-b578-5b5392b571df"
"b05e124f-c7cc-45a0-a6aa-8cf78c946968"
)
}
Set-MgGroupLicense -GroupId $groupId -BodyParameter $params
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.groups.item.assign_license.assign_license_post_request_body import AssignLicensePostRequestBody
from msgraph.generated.models.assigned_license import AssignedLicense
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AssignLicensePostRequestBody(
add_licenses = [
],
remove_licenses = [
UUID("c7df2760-2c81-4ef7-b578-5b5392b571df"),
UUID("b05e124f-c7cc-45a0-a6aa-8cf78c946968"),
],
)
result = await graph_client.groups.by_group_id('group-id').assign_license.post(request_body)
Para obtener más información sobre cómo agregar el SDK al proyecto y crear una instancia de authProvider, consulte la documentación del SDK.
Respuesta
La respuesta es el objeto de grupo actualizado.
Nota: El objeto de respuesta que se muestra aquí puede acortarse para mejorar la legibilidad.
HTTP/1.1 202 Accepted
Content-type: application/json
location: https://graph.microsoft.com/v2/d056d009-17b3-4106-8173-cd3978ada898/directoryObjects/1ad75eeb-7e5a-4367-a493-9214d90d54d0/Microsoft.DirectoryServices.Group
{
"id": "1ad75eeb-7e5a-4367-a493-9214d90d54d0",
"deletedDateTime": null,
"classification": null,
"createdDateTime": "2018-04-18T22:05:03Z",
"securityEnabled": true
}