Escolha a permissão ou permissões marcadas como menos privilegiadas para esta API. Utilize uma permissão ou permissões com privilégios mais elevados apenas se a sua aplicação o exigir. Para obter detalhes sobre as permissões delegadas e de aplicação, veja Tipos de permissão. Para saber mais sobre estas permissões, veja a referência de permissões.
Tipo de permissão
Permissões com menos privilégios
Permissões com privilégios superiores
Delegado (conta corporativa ou de estudante)
LicenseAssignment.ReadWrite.All
Directory.ReadWrite.All, Group.ReadWrite.All
Delegado (conta pessoal da Microsoft)
Sem suporte.
Sem suporte.
Application
LicenseAssignment.ReadWrite.All
Directory.ReadWrite.All, Group.ReadWrite.All
Importante
Em cenários delegados com contas escolares ou profissionais, tem de ser atribuída ao utilizador com sessão iniciada uma função de Microsoft Entra suportada ou uma função personalizada com a permissão de microsoft.directory/groups/assignLicense função. As seguintes funções com menos privilégios são suportadas para esta operação:
Uma coleção de objetos assignedLicense que especifica as licenças a adicionar. Pode desativar servicePlans associados a uma licença ao definir a propriedade disabledPlans num objeto assignedLicense .
removeLicenses
Coleção de GUIDs
Uma coleção de skuIds que identificam as licenças a remover. Obrigatório. Pode ser uma coleção vazia.
Resposta
Se for bem-sucedido, este método devolve um 202 Accepted código de resposta e um objeto de grupo de destino no corpo da resposta.
// 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://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].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.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);
# 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://video2.skills-academy.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)
// 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://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].AssignLicense.PostAsync(requestBody);
// 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://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
assignLicense, err := graphClient.Groups().ByGroupId("group-id").AssignLicense().Post(context.Background(), requestBody, nil)
// 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);
<?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();
# 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://video2.skills-academy.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)