取得已開立發票的商業使用量明細項目
注意
在 2025 年 1 月 21 日之後,您可以繼續使用此 API,但不適用於每個計費週期。 以下說明如何根據您的需求選擇正確的版本:
目標:從 2022 年 9 月到 2024 年 12 月,擷取計費期間的每日分級使用量明細專案。
動作:除非您已切換至 API v2 GA,否則請使用此 API,直到 2025 年 1 月 21 日為止。
目標:在 2022 年 9 月之前擷取計費期間的每日分級使用量明細專案。
動作:獨佔使用此 API。
目標:從 2022 年 9 月起擷取計費期間的每日評分使用量明細專案,但只在 2025 年 1 月 21 日之後。
動作:僅使用 API v2 GA。
若要順暢地轉換至新的 API,請遵循此連結: 計費和未計費的每日評等使用量對帳 API v2 (GA) 。
感謝您的注意,我們期待著您的計費 API 持續成功。
您可以使用下列方法來取得指定發票的商業消費發票明細專案的詳細數據集合(也稱為已關閉的每日評分使用量明細專案)。
重要
每日評等使用量數據不包含這些產品的費用:
- Azure 保留
- Azure 節省方案
- Office
- Dynamics
- Microsoft Power Apps
- 永久軟體
- 軟體訂閱
- 非Microsoft或 Marketplace SaaS 產品
必要條件
認證,如合作夥伴中心驗證所述。 此案例支援使用獨立應用程式和 App+使用者認證進行驗證。
要為其取得明細專案的發票標識碼。
C#
若要取得指定發票的商業明細專案,您必須擷取發票物件:
提供者會識別計費詳細資訊的來源(例如一次)。 InvoiceLineItemType 會指定類型(例如 UsageLineItem)。
下列範例程式代碼會使用 foreach 循環來處理行專案集合。 系統會 為每個 InvoiceLineItemType 擷取個別的明細專案集合。
若要取得對應至 InvoiceDetail 實例的明細專案集合:
將實例的 BillingProvider 和 InvoiceLineItemType 傳遞至 By 方法。
呼叫 Get 或 GetAsync 方法來擷取相關聯的明細專案。
建立列舉值以周游集合,如下列範例所示。
// IAggregatePartner partnerOperations;
// string invoiceId;
// string curencyCode;
// string period;
// int pageMaxSizeReconLineItems = 2000;
// all the operations executed on this partner operation instance will share the same correlation Id but will differ in request Id
IPartner scopedPartnerOperations = partnerOperations.With(RequestContextFactory.Instance.Create(Guid.NewGuid()));
var seekBasedResourceCollection = scopedPartnerOperations.Invoices.ById(invoiceId).By("onetime", "usagelineitems", curencyCode, period, pageMaxSizeReconLineItems).Get();
var fetchNext = true;
ConsoleKeyInfo keyInfo;
var itemNumber = 1;
while (fetchNext)
{
Console.Out.WriteLine("\tLine line items count: " + seekBasedResourceCollection.Items.Count());
seekBasedResourceCollection.Items.ToList().ForEach(item =>
{
// Instance of type DailyRatedUsageLineItem
if (item is DailyRatedUsageLineItem)
{
Type t = typeof(DailyRatedUsageLineItem);
PropertyInfo[] properties = t.GetProperties();
foreach (PropertyInfo property in properties)
{
// Insert code here to work with the line item properties
}
}
itemNumber++;
});
Console.Out.WriteLine("\tPress any key to fetch next data. Press the Escape (Esc) key to quit: \n");
keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.Escape)
{
break;
}
fetchNext = !string.IsNullOrWhiteSpace(seekBasedResourceCollection.ContinuationToken);
if (fetchNext)
{
if (seekBasedResourceCollection.Links.Next.Headers != null && seekBasedResourceCollection.Links.Next.Headers.Any())
{
seekBasedResourceCollection = scopedPartnerOperations.Invoices.ById(invoiceId).By("onetime", "usagelineitems", curencyCode, period, pageMaxSizeReconLineItems).Seek(seekBasedResourceCollection.ContinuationToken, SeekOperation.Next);
}
}
}
請參閱範例:
- 範例: 控制台測試應用程式
- 專案: 合作夥伴中心 SDK 範例
- 類別: GetBilledConsumptionReconLineItemsPaging.cs
REST 要求
要求語法
使用第一個語法可傳回指定發票之每個明細專案的完整清單。 對於大型發票,請使用第二個語法搭配指定的大小和0起始的位移,以傳回分頁明細專案清單。 使用第三個語法,使用 取得下一頁的對帳明細專案 seekOperation = "Next"
。
方法 | 要求 URI |
---|---|
GET | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode} HTTP/1.1 |
取得 | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&size={size} HTTP/1.1 |
取得 | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&size={size}&seekOperation=Next |
URI 參數
建立要求時,請使用下列 URI 和查詢參數。
名稱 | 類型 | 必要 | 描述 |
---|---|---|---|
invoice-id | 字串 | Yes | 識別發票的字串。 |
Provider - 提供者 | 字串 | Yes | 提供者:「OneTime」。 |
invoice-line-item-type | 字串 | Yes | 發票詳細數據的類型:「UsageLineItems」。 |
currencyCode | 字串 | Yes | 計費明細項目的貨幣代碼。 |
Period | 字串 | Yes | 計費對帳的期間。 範例:目前、上一個。 |
size | 數值 | No | 要傳回的項目數上限。 默認大小為 2000 |
seekOperation | 字串 | No | 設定 seekOperation=Next 以取得對帳明細專案的下一頁。 |
要求標頭
如需詳細資訊,請參閱合作夥伴中心 REST 標頭。
要求本文
無。
REST 回應
如果成功,回應會包含明細專案詳細數據的集合。
對於明細專案 ChargeType,購買值會對應至 New。 [退款] 值會對應至 Cancel。
回應成功和錯誤碼
每個回應都有一個 HTTP 狀態代碼,指出成功或失敗和其他偵錯資訊。 使用網路追蹤工具來讀取此程式代碼、錯誤類型等等參數。 如需完整清單,請參閱合作夥伴中心的 REST 錯誤碼。
REST 範例
要求回應範例 1
此範例 REST 要求和回應的詳細資料如下:
- 提供者: OneTime
- InvoiceLineItemType: UsageLineItems
- 期間:上一個
要求範例 1
GET https://api.partnercenter.microsoft.com/v1/invoices/T000001234/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000 HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 1234ecb8-37af-45f4-a1a1-358de3ca2b9e
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Host: api.partnercenter.microsoft.com
重要
自 2023 年 6 月起,最新的合作夥伴中心 .NET SDK 3.4.0 版現已封存。 您可以從 GitHub 下載 SDK 版本,以及 包含實用資訊的自述檔 。
鼓勵合作夥伴繼續使用 合作夥伴中心 REST API。
回應範例 1
HTTP/1.1 200 OK
Content-Length: 2484
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 1234ecb8-37af-45f4-a1a1-358de3ca2b9e
MS-CV: bpqyomePDUqrSSYC.0
MS-ServerId: 202010406
Date: Wed, 20 Feb 2019 19:59:27 GMT
{
"totalCount": 2,
"items": [
{
"partnerId": "2b8940db-5089-539c-e757-520ed1d1bc88",
"partnerName": "",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "T000001234",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "Test Test on Windows 2012 R2 (WebHost)",
"productName": "Test Test on Windows",
"publisherName": "Test",
"publisherId": "28503520",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Subscription 10",
"chargeStartDate": "2018-11-01T00:00:00Z",
"chargeEndDate": "2018-12-01T00:00:00Z",
"usageDate": "2018-11-13T00:00:00Z",
"meterType": "1 Compute Hour - 1core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "1core",
"meterSubCategory": "Test Test on Windows",
"meterName": "Test Test on Windows - Test Test on Windows 2012 R2 (WebHost) - 1 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS2",
"consumedService": "Microsoft.Compute",
"resourceGroup": "TestWINRG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/TestWINRG/providers/Microsoft.Compute/virtualMachines/testWinTest",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_B1s\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "new",
"unitPrice": 0.0209496384791679,
"quantity": 23.200004,
"unitType": "1 Hour",
"billingPreTaxTotal": 0.486031696515249,
"billingCurrency": "USD",
"pricingPreTaxTotal": 0.486031696515249,
"pricingCurrency": "USD",
"entitlementId": "3f47bcf1-965d-40a1-a2bc-3d5db3653250",
"entitlementDescription": "Partner Subscription",
"pcToBCExchangeRate": 1,
"pcToBCExchangeRateDate": "2019-08-01T00:00:00Z",
"effectiveUnitPrice": 0,
"rateOfPartnerEarnedCredit": 0,
"rateOfCredit": 0,
"creditType": "Credit Not Applied",
"invoiceLineItemType": "usage_line_items",
"billingProvider": "marketplace",
"benefitOrderId": "5ea053d6-4a0d-46ef-bc82-15065b475d01",
"benefitId": "28ddab06-2c5b-479e-88bb-7b7bfda4e7fd",
"benefitType": "SavingsPlan",
"attributes": {
"objectType": "DailyRatedUsageLineItem"
}
},
{
"partnerId": "2b8940db-5089-539c-e757-520ed1d1bc88",
"partnerName": "",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "T000001234",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "Test Test on Ubuntu 16.04 (WebHost)",
"productName": "Test Test on Linux",
"publisherName": "Test",
"publisherId": "28503520",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Subscription 10",
"chargeStartDate": "2018-11-01T00:00:00Z",
"chargeEndDate": "2018-12-01T00:00:00Z",
"usageDate": "2018-11-13T00:00:00Z",
"meterType": "1 Compute Hour - 1core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "1core",
"meterSubCategory": "Test Test on Linux",
"meterName": "Test Test on Linux - Test Test on Ubuntu 16.04 (WebHost) - 1 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS",
"consumedService": "Microsoft.Compute",
"resourceGroup": "TESTRG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/TestRG/providers/Microsoft.Compute/virtualMachines/testUbuntuTest",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_B1s\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "new",
"unitPrice": 0.0209951014286867,
"quantity": 23.350007,
"unitType": "1 Hour",
"billingPreTaxTotal": 0.490235765325545,
"billingCurrency": "USD",
"pricingPreTaxTotal": 0.490235765325545,
"pricingCurrency": "USD",
"entitlementId": "66bada28-271e-4b7a-aaf5-c0ead6312345",
"entitlementDescription": "Partner Subscription",
"pcToBCExchangeRate": 1,
"pcToBCExchangeRateDate": "2019-08-01T00:00:00Z",
"effectiveUnitPrice": 0.1999968000511991808131,
"rateOfPartnerEarnedCredit": 0,
"rateOfCredit": 1,
"creditType": "Azure Credit Applied",
"invoiceLineItemType": "usage_line_items",
"billingProvider": "marketplace",
"benefitOrderId": "",
"benefitId": "",
"benefitType": "Charge",
"attributes": {
"objectType": "DailyRatedUsageLineItem"
}
}
],
"links": {
"self": {
"uri": "/invoices/T000001234/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000",
"method": "GET",
"headers": []
},
"next": {
"uri": "/invoices/T000001234/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000&seekOperation=Next",
"method": "GET",
"headers": [
{
"key": "MS-ContinuationToken",
"value": "AQAAAA=="
}
]
}
},
"attributes": {
"objectType": "Collection"
}
}
要求回應範例 2
此範例 REST 要求和回應的詳細資料如下:
- 提供者: OneTime
- InvoiceLineItemType: UsageLineItems
- 期間:上一個
- SeekOperation: 下一步
要求範例 2
GET https://api.partnercenter.microsoft.com/v1/invoices/T000001234/lineitems?provider=onetime&invoiceLineItemType=usagelineitems¤cyCode=usd&period=previous&size=2000&seekoperation=next HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-ContinuationToken: d19617b8-fbe5-4684-a5d8-0230972fb0cf,0705c4a9-39f7-4261-ba6d-53e24a9ce47d_a4ayc/80/OGda4BO/1o/V0etpOqiLx1JwB5S3beHW0s=,0d81c700-98b4-4b13-9129-ffd5620f72e7
MS-RequestId: 1234ecb8-37af-45f4-a1a1-358de3ca2b9e
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
MS-PartnerCenter-Application: Partner Center .NET SDK Samples
Host: api.partnercenter.microsoft.com
回應範例 2
HTTP/1.1 200 OK
Content-Length: 2484
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 1234ecb8-37af-45f4-a1a1-358de3ca2b9e
MS-CV: bpqyomePDUqrSSYC.0
MS-ServerId: 202010406
Date: Wed, 20 Feb 2019 19:59:27 GMT
{
"totalCount": 1,
"items": [
{
"partnerId": "2b8940db-5089-539c-e757-520ed1d1bc88",
"partnerName": "",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "T000001234",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "Test Test on Windows 2012 R2 (WebHost)",
"productName": "Test Test on Windows",
"publisherName": "Test",
"publisherId": "28503520",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Subscription 10",
"chargeStartDate": "2018-11-01T00:00:00Z",
"chargeEndDate": "2018-12-01T00:00:00Z",
"usageDate": "2018-11-13T00:00:00Z",
"meterType": "1 Compute Hour - 1core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "1core",
"meterSubCategory": "Test Test on Windows",
"meterName": "Test Test on Windows - Test Test on Windows 2012 R2 (WebHost) - 1 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS2",
"consumedService": "Microsoft.Compute",
"resourceGroup": "TestWINRG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/TestWINRG/providers/Microsoft.Compute/virtualMachines/testWinTest",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_B1s\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "new",
"unitPrice": 0.0209496384791679,
"quantity": 23.200004,
"unitType": "1 Hour",
"billingPreTaxTotal": 0.486031696515249,
"billingCurrency": "USD",
"pricingPreTaxTotal": 0.486031696515249,
"pricingCurrency": "USD",
"entitlementId": "66bada28-271e-4b7a-aaf5-c0ead6312345",
"entitlementDescription": "Partner Subscription",
"pcToBCExchangeRate": 1,
"pcToBCExchangeRateDate": "2019-08-01T00:00:00Z",
"effectiveUnitPrice": 0.1835431430074643112595,
"rateOfPartnerEarnedCredit": 0.15,
"rateOfCredit": 0.15,
"creditType": "Partner Earned Credit Applied",
"benefitOrderId": "",
"benefitId": "",
"benefitType": "Charge",
"attributes": {
"objectType": "DailyRatedUsageLineItem"
}
}
],
"links": {
"self": {
"uri": "/invoices/T000001234/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000",
"method": "GET",
"headers": []
}
},
"attributes": {
"objectType": "Collection"
}
}