获取权利集合
如何获取权利集合。
先决条件
合作伙伴中心身份验证中所述的凭据。 此方案支持使用应用凭据和用户凭据进行身份验证。
客户 ID (
customer-tenant-id
)。 如果不知道客户的 ID,可以通过选择“客户”工作区,然后从客户列表中选择客户,然后选择“帐户”,在合作伙伴中心中查找该 ID。 在客户的“帐户”页上,在“客户帐户信息”部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id
) 相同。
C#
若要获取客户的权利集合,请使用客户 ID 调用 IAggregatePartner.Customers.ById() 方法来获取权利操作的接口,以标识客户。 然后,从 Entitlements 属性检索接口,并调用 Get() 或 GetAsync() 方法来检索权利集合。
IAggregatePartner partnerOperations;
string customerId;
// Get the collection of entitlements.
var entitlements = partnerOperations.Customers.ById(customerId).Entitlements.Get();
若要填充要检索的权利的到期日期,请调用上述相同方法,并将可选的布尔参数 showExpiry 设置为 true Get(true) 或 GetAsync(true)。 这表示需要权利到期日期(如果适用)。
重要
本地权利类型没有到期日期。
REST 请求
请求语法
方法 | 请求 URI |
---|---|
GET | {baseURL}/v1/customers/{customerId}/entitlements HTTP/1.1 |
URI 参数
创建请求时,请使用以下路径和查询参数。
名称 | 类型 | 必需 | 说明 |
---|---|---|---|
customerId | string | 是 | 标识客户的 GUID 格式 customerId。 |
entitlementType | string | 否 | 可用于指定要检索的权利的类型(软件 或 reservedInstance )。 如果未设置,将检索所有类型 |
showExpiry | boolean | 否 | 指示是否要求权利到期日期的可选标志。 |
请求标头
有关详细信息,请参阅合作伙伴中心 REST 标头。
请求正文
无。
请求示例
GET https://api.partnercenter.microsoft.com/v1/customers/18ac2950-8ea9-4dfc-92a4-ff4d4cd57796/entitlements HTTP/1.1
Authorization: Bearer <Token>
Accept: application/json
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Host: api.partnercenter.microsoft.com
REST 响应
如果成功,响应正文将包含权利资源的集合。
响应的成功和错误代码
每个响应都有一个 HTTP 状态代码,指示成功或失败和其他调试信息。 使用网络跟踪工具读取此代码、错误类型和其他参数。 有关完整列表,请参阅错误代码。
响应示例
HTTP/1.1 200 OK
Content-Length: 103778
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
X-Locale: en-US
MS-CV: EjFdw8fCpkKyMyza.0
MS-ServerId: 000002
Date: Mon, 19 Mar 2018 07:42:51 GMT
{
"totalCount": 2,
"items": [
{
"includedEntitlements": [],
"referenceOrder": {
"id": "KaJ8XvkKc_GoNZOUyjVaRJalTBN5MWdV1",
"lineItemId": "0"
},
"productId": "DZH318Z0BQ3W",
"quantity": 1,
"entitledArtifacts": [
{
"link": {
"uri": "/customers/18ac2950-8ea9-4dfc-92a4-ff4d4cd57796/artifacts/reservedinstance/groups/2caf524395724e638ef64e109f1f79ca/lineitems/03500b1b-f2d6-4e23-ab4b-9fd67b917012/resource/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
"method": "GET",
"headers": []
},
"resourceId": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
"artifactType": "reservedinstance"
}
],
"skuId": "007J",
"entitlementType": "reservedinstance"
"dynamicAttributes": {
"reservationType": "virtualmachines"
}
},
{
"includedEntitlements": [
{
"includedEntitlements": [],
"referenceOrder": {
"id": "NUXMSvmS20EQ4kFsZmzkSqb747fqKmNk1",
"lineItemId": "0"
},
"productId": "DG7GMGF0DWTJ",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0001",
"entitlementType": "software"
},
{
"includedEntitlements": [],
"referenceOrder": {
"id": "NUXMSvmS20EQ4kFsZmzkSqb747fqKmNk1",
"lineItemId": "0"
},
"productId": "DG7GMGF0DWLG",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0002",
"entitlementType": "software"
}
],
"referenceOrder": {
"id": "NUXMSvmS20EQ4kFsZmzkSqb747fqKmNk1",
"lineItemId": "0"
},
"productId": "DG7GMGF0DWTK",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0002",
"entitlementType": "software"
}
],
"attributes": {
"objectType": "Collection"
}
}
更多示例
以下示例演示如何检索特定类型的权利以及到期日期(如果适用)
C# 示例
若要检索特定类型的权利,请从权利接口获取 ByEntitlementType 接口,并使用 Get() 或 GetAsync() 方法。
ResourceCollection<Entitlement> entitlements = partnerOperations.Customers.ById(selectedCustomerId).Entitlements.ByEntitlementType("software").Get(true);
请求示例
GET https://api.partnercenter.microsoft.com/v1/customers/de3dcef9-9991-459c-ac71-2903d1127414/entitlements?entitlementtype=software&showExpiry=true
Authorization: Bearer <Token>
Accept: application/json
MS-RequestId: 6517a410-67ce-4995-9bb7-116a52179f92
MS-CorrelationId: bbbb1111-cc22-3333-44dd-555555eeeeee
X-Locale: en-US
Host: api.partnercenter.microsoft.com
响应示例
HTTP/1.1 200 OK
Content-Length: 1791
Content-Type: application/json; charset=utf-8
MS-CorrelationId: bbbb1111-cc22-3333-44dd-555555eeeeee
MS-RequestId: 6517a410-67ce-4995-9bb7-116a52179f92
X-Locale: en-US
MS-CV: yD+4LBKePUSp/vqJ.0
MS-ServerId: 000002
Date: Mon, 28 Jan 2019 18:31:43 GMT
{
"totalCount": 2,
"items": [
{
"includedEntitlements": [
{
"includedEntitlements": [],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "0",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWM2",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0001",
"entitlementType": "software"
},
{
"includedEntitlements": [],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "0",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWMK",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0001",
"entitlementType": "software"
}
],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "0",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWM3",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0002",
"entitlementType": "software"
},
{
"includedEntitlements": [
{
"includedEntitlements": [],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "1",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWV1",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0002",
"entitlementType": "software"
},
{
"includedEntitlements": [],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "1",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWV2",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0002",
"entitlementType": "software"
}
],
"referenceOrder": {
"id": "4teYMtWYEeKM77JftGLIQYMOZPTwyOEV1",
"lineItemId": "1",
"alternateId": "8f3af3dea1ea"
},
"productId": "DG7GMGF0DWBQ",
"quantity": 1,
"entitledArtifacts": [],
"skuId": "0003",
"entitlementType": "software",
"expiryDate": "2022-01-28T00:00:00Z"
}
],
"attributes": {
"objectType": "Collection"
}
}
以下示例演示如何从权利检索有关产品和预留的信息。
使用 SDK V1.8 从权利中检索虚拟机预留详细信息
C# 示例
若要从权利中检索与虚拟机预留相关的更多详细信息,请使用 artifactType = virtual_machine_reserved_instance 调用在 entitledArtifacts.link 下公开的 URI。
ResourceCollection<Entitlement> entitlements = partnerOperations.Customers.ById(selectedCustomerId).Entitlements.ByEntitlementType("VirtualMachineReservedInstance").Get();
((VirtualMachineReservedInstanceArtifact)entitlements.First().EntitledArtifacts.First(x => x.Type == ArtifactType.VirtualMachineReservedInstance)).Link.InvokeAsync<VirtualMachineReservedInstanceArtifactDetails>(partnerOperations)
请求示例
GET https://api.partnercenter.microsoft.com/v1/customers/18ac2950-8ea9-4dfc-92a4-ff4d4cd57796/artifacts/virtualmachinereservedinstance/groups/2caf524395724e638ef64e109f1f79ca/lineitems/03500b1b-f2d6-4e23-ab4b-9fd67b917012/resource/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1 HTTP/1.1
Authorization: Bearer <Token>
Accept: application/json
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Host: api.partnercenter.microsoft.com
响应示例
HTTP/1.1 200 OK
Content-Length: 368
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
X-Locale: en-US
MS-CV: yrdTGsZ7IU2v9okv.0
MS-ServerId: 000002
Date: Mon, 19 Mar 2018 07:45:14 GMT
{
"type": "virtual_machine_reserved_instance",
"virtualMachineReservations": [
{
"reservationId": "99f320db-c029-4c1b-a157-dad76e4481b6",
"scopeType": "Shared",
"quantity": 1,
"expiryDateTime": "2019-02-23T00:00:00",
"effectiveDateTime": "2018-02-23T18:15:24.6724884Z",
"provisioningState": "Created"
}
]
}
使用 SDK V1.9 从权利中检索预留详细信息
C# 示例
若要从预留实例权利中检索与预留相关的更多详细信息,请调用下面 entitledArtifacts.link
公开的 artifactType = reservedinstance
URI。
ResourceCollection<Entitlement> entitlements = partnerOperations.Customers.ById(selectedCustomerId).Entitlements.ByEntitlementType("ReservedInstance").Get();
((ReservedInstanceArtifact)entitlements.First().EntitledArtifacts.First(x => x.Type == ArtifactType.ReservedInstance)).Link.InvokeAsync<ReservedInstanceArtifactDetails>(partnerOperations);
请求示例
GET https://api.partnercenter.microsoft.com/v1/customers/18ac2950-8ea9-4dfc-92a4-ff4d4cd57796/artifacts/reservedinstance/groups/2caf524395724e638ef64e109f1f79ca/lineitems/03500b1b-f2d6-4e23-ab4b-9fd67b917012/resource/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1 HTTP/1.1
Authorization: Bearer <Token>
Accept: application/json
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Host: api.partnercenter.microsoft.com
响应示例
HTTP/1.1 200 OK
Content-Length: 368
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: cdc428d2-035b-41c4-9a32-e643c4471cbd
X-Locale: en-US
MS-CV: yrdTGsZ7IU2v9okv.0
MS-ServerId: 000002
Date: Mon, 19 Mar 2018 07:45:14 GMT
{
"type": "reservedinstance",
"virtualMachineReservations": [
{
"reservationId": "99f320db-c029-4c1b-a157-dad76e4481b6",
"scopeType": "Shared",
"quantity": 1,
"expiryDateTime": "2019-02-23T00:00:00",
"effectiveDateTime": "2018-02-23T18:15:24.6724884Z",
"provisioningState": "Created"
}
]
}
API 使用者
使用 API 查询虚拟机预留实例权利的合作伙伴 - 将 /customers/{customerId}/entitlements 的请求 URI 更新为 /customers/{customerId}/entitlements?entitlementType=virtualmachinereservedinstance 以保持向后兼容性。 若要使用具有增强合同的虚拟机或 Azure SQL,请将请求 URI 更新为 /customers/{customerId}/entitlements?entitlementType=reservedinstance。