用户:assignLicense
命名空间:microsoft.graph 为用户添加或删除订阅。还可以启用和禁用与订阅相关的特定计划。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
User.ReadWrite.All、Directory.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
User.ReadWrite.All、Directory.ReadWrite.All |
HTTP 请求
POST /users/{id | userPrincipalName}/assignLicense
| 标头 |
值 |
| Authorization |
Bearer {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" ]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var addLicenses = new List<AssignedLicense>()
{
new AssignedLicense
{
DisabledPlans = new List<Guid>()
{
Guid.Parse("11b0131d-43c8-4bbb-b2c8-e80f9a50834a")
},
SkuId = Guid.Parse("45715bb8-13f9-4bf6-927f-ef96c102d394")
}
};
var removeLicenses = new List<Guid>()
{
Guid.Parse("bea13e0c-3828-4daa-a392-28af7ff61a0f")
};
await graphClient.Me
.AssignLicense(addLicenses,removeLicenses)
.Request()
.PostAsync();
有关如何将 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 文档。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/assignLicense"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
NSMutableArray *addLicensesList = [[NSMutableArray alloc] init];
MSGraphAssignedLicense *addLicenses = [[MSGraphAssignedLicense alloc] init];
NSMutableArray *disabledPlansList = [[NSMutableArray alloc] init];
[disabledPlansList addObject: @"11b0131d-43c8-4bbb-b2c8-e80f9a50834a"];
[addLicenses setDisabledPlans:disabledPlansList];
[addLicenses setSkuId:@"45715bb8-13f9-4bf6-927f-ef96c102d394"];
[addLicensesList addObject: addLicenses];
payloadDictionary[@"addLicenses"] = addLicensesList;
NSMutableArray *removeLicensesList = [[NSMutableArray alloc] init];
[removeLicensesList addObject: @"bea13e0c-3828-4daa-a392-28af7ff61a0f"];
payloadDictionary[@"removeLicenses"] = removeLicensesList;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 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.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
requestBody.SetAddLicenses( []AssignedLicense {
msgraphsdk.NewAssignedLicense(),
SetAdditionalData(map[string]interface{}{
"disabledPlans": []String {
"11b0131d-43c8-4bbb-b2c8-e80f9a50834a",
}
"skuId": "45715bb8-13f9-4bf6-927f-ef96c102d394",
}
}
requestBody.SetRemoveLicenses( []String {
"bea13e0c-3828-4daa-a392-28af7ff61a0f",
}
result, err := graphClient.Me().AssignLicense().Post(requestBody)
有关如何将 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"
}