用户:assignLicense
本文内容
命名空间:microsoft.graph 添加或删除用户的订阅。 还可以启用和禁用与订阅相关的特定计划。
权限
调用此 API 需要以下权限之一。 若要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
User.ReadWrite.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
User.ReadWrite.All、Directory.ReadWrite.All
HTTP 请求
POST /users/{id | userPrincipalName}/assignLicense
标头
值
Authorization
持有者 {token}。 必填。
Content-Type
application/json
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
响应
如果成功,此方法在响应正文中返回 200 OK
响应代码和 user 对象。
示例
下面是一个如何调用此 API 的示例。
请求
下面是一个请求示例。
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" ]
}
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);
有关如何 将 SDK 添加到 项目并 创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
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);
有关如何 将 SDK 添加到 项目并 创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
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();
有关如何 将 SDK 添加到 项目并 创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.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 := []graphmodels.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)
有关如何 将 SDK 添加到 项目并 创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
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
有关如何 将 SDK 添加到 项目并 创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
响应
下面是一个响应示例。 注意:为了提高可读性,可能缩短了此处显示的响应对象。
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"
}