取得權利的集合
本文內容
必要條件
C#
REST 要求
REST 回應
更多範例
如何取得權利集合。
認證,如合作夥伴中心驗證 所述。 此案例支援使用應用程式加上使用者的認證來進行驗證。
客戶識別碼 (customer-tenant-id
)。 如果您不知道客戶的標識碼,您可以在合作夥伴中心中選取 [客戶 ] 工作區,然後從客戶清單中查看客戶,然後從 [帳戶 ]。 在客戶的 [帳戶] 頁面上,在 [客戶帳戶資訊] 區段中尋找 Microsoft 標識符 。 Microsoft 識別碼與客戶識別碼 (customer-tenant-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) 。 這表示需要權利到期日(適用時)。
展開資料表
方法
要求 URI
GET
{baseURL} /v1/customers/{customerId}/entitlements HTTP/1.1
建立要求時,請使用下列路徑和查詢參數。
展開資料表
名稱
類型
必要
描述
customerId
字串
Yes
識別客戶的 GUID 格式化 customerId。
entitlementType
字串
No
可用來指定要擷取的權利類型(軟體 或 reservedInstance )。 如果未設定,則會擷取所有類型
showExpiry
boolean
No
選擇性旗標,指出是否需要權利到期日。
如需詳細資訊,請參閱合作夥伴中心 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
如果成功,回應本文會包含權利資源的集合 。
每個回應都有一個 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"
}
}
下列範例示範如何擷取特定類型的權利以及到期日(適用時)
若要擷取特定類型的權利,請從 Entitlements 介面取得 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 從權利擷取虛擬機保留詳細數據
若要從權利擷取與虛擬機保留相關的更多詳細數據,請使用 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"
}
]
}
若要從保留實例權利擷取與保留相關的更多詳細數據,請使用 叫用 artifactType = reservedinstance
公開的 entitledArtifacts.link
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 查詢虛擬機保留實例權利的合作夥伴 - 將 /customers/{customerId}/entitlements 的要求 URI 更新為 /customers/{customerId}/entitlements?entitlementType=virtualmachinereservedinstance 以維持回溯兼容性。 若要使用具有增強型合約的虛擬機或 Azure SQL,請將要求 URI 更新為 /customers/{customerId}/entitlements?entitlementType=reservedinstance 。