Пространство имен: microsoft.graph
Важно!
API версии /beta
в Microsoft Graph могут быть изменены. Использование этих API в производственных приложениях не поддерживается. Чтобы определить, доступен ли API в версии 1.0, используйте селектор версий.
Добавление или удаление лицензий в группе. Лицензии, назначенные группе, будут назначены всем пользователям в группе. Лицензирование на основе групп является альтернативой прямому лицензированию пользователей. Дополнительные сведения о групповом лицензировании см. в статье Что такое групповое лицензирование в Microsoft Entra ID.
Чтобы получить подписки, доступные в каталоге, выполните запрос GET subscribedSkus.
Этот API доступен в следующих национальных облачных развертываниях.
Глобальная служба |
Правительство США L4 |
Правительство США L5 (DOD) |
Китай управляется 21Vianet |
✅ |
✅ |
✅ |
✅ |
Разрешения
Выберите разрешение или разрешения, помеченные как наименее привилегированные для этого API. Используйте более привилегированное разрешение или разрешения только в том случае, если это требуется приложению. Дополнительные сведения о делегированных разрешениях и разрешениях приложений см. в разделе Типы разрешений. Дополнительные сведения об этих разрешениях см. в справочнике по разрешениям.
Тип разрешения |
Разрешения с наименьшими привилегиями |
Более высокие привилегированные разрешения |
Делегированные (рабочая или учебная учетная запись) |
LicenseAssignment.ReadWrite.All |
Directory.ReadWrite.All, Group.ReadWrite.All |
Делегированные (личная учетная запись Майкрософт) |
Не поддерживается. |
Не поддерживается. |
Приложение |
LicenseAssignment.ReadWrite.All |
Directory.ReadWrite.All, Group.ReadWrite.All |
Важно!
В делегированных сценариях с рабочими или учебными учетными записями вошедшему пользователю должна быть назначена поддерживаемая роль Microsoft Entra или настраиваемая роль с разрешением ролиmicrosoft.directory/groups/assignLicense
. Для этой операции поддерживаются следующие наименее привилегированные роли:
- Запись каталогов
- Администратор Группы
- Администратор лицензий
- Администратор пользователей
HTTP-запрос
POST /groups/{id}/assignLicense
Текст запроса
В тексте запроса предоставьте JSON-объект с указанными ниже параметрами.
Параметр |
Тип |
Описание |
addLicenses |
Коллекция assignedLicense |
Коллекция объектов assignedLicense, указывающих добавляемые лицензии. Вы можете отключить servicePlans, связанные с лицензией, задав свойство disabledPlans для объекта assignedLicense . |
removeLicenses |
Коллекция объектов Guid |
Коллекция идентификаторов skuId, которые определяют удаляемые лицензии. Обязательно. Может быть пустой коллекцией. |
Отклик
В случае успешного выполнения этот метод возвращает код отклика 202 Accepted
и объект целевой группы в тексте ответа.
Примеры
Пример 1. Добавление лицензий в группу
В следующем примере в группу добавляются лицензии.
Запрос
POST https://graph.microsoft.com/beta/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.Beta.Groups.Item.AssignLicense;
using Microsoft.Graph.Beta.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);
mgc-beta groups assign-license post --group-id {group-id} --body '{\
"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 major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-beta-sdk-go/groups"
graphmodels "github.com/microsoftgraph/msgraph-beta-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)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.groups.item.assignlicense.AssignLicensePostRequestBody assignLicensePostRequestBody = new com.microsoft.graph.beta.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);
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')
.version('beta')
.post(group);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Groups\Item\AssignLicense\AssignLicensePostRequestBody;
use Microsoft\Graph\Beta\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();
Import-Module Microsoft.Graph.Beta.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-MgBetaGroupLicense -GroupId $groupId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.groups.item.assign_license.assign_license_post_request_body import AssignLicensePostRequestBody
from msgraph_beta.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)
Отклик
Ответ — это обновленный объект группы.
Примечание. Объект отклика, показанный здесь, может быть сокращен для удобочитаемости.
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
}
Пример 2. Удаление лицензий из группы
В следующем примере лицензии удаляются из группы.
Запрос
POST https://graph.microsoft.com/beta/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.Beta.Groups.Item.AssignLicense;
using Microsoft.Graph.Beta.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);
mgc-beta groups assign-license post --group-id {group-id} --body '{\
"addLicenses": [],\
"removeLicenses": [\
"c7df2760-2c81-4ef7-b578-5b5392b571df",\
"b05e124f-c7cc-45a0-a6aa-8cf78c946968"\
]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-beta-sdk-go/groups"
graphmodels "github.com/microsoftgraph/msgraph-beta-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)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.groups.item.assignlicense.AssignLicensePostRequestBody assignLicensePostRequestBody = new com.microsoft.graph.beta.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);
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')
.version('beta')
.post(group);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Groups\Item\AssignLicense\AssignLicensePostRequestBody;
use Microsoft\Graph\Beta\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();
Import-Module Microsoft.Graph.Beta.Groups
$params = @{
addLicenses = @(
)
removeLicenses = @(
"c7df2760-2c81-4ef7-b578-5b5392b571df"
"b05e124f-c7cc-45a0-a6aa-8cf78c946968"
)
}
Set-MgBetaGroupLicense -GroupId $groupId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.groups.item.assign_license.assign_license_post_request_body import AssignLicensePostRequestBody
from msgraph_beta.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)
Отклик
Ответ — это обновленный объект группы.
Заметка: Объект ответа, показанный здесь, может быть сокращен для удобства чтения.
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
}