获取发票未计费商业使用量明细项目
注意
自 2025 年 1 月 21 日起,此 API 将弃用。 规划过渡以确保连续性。
目标:在 2025 年 1 月 21 日之前检索当前和以前的计费周期的未计费每日使用行项。
操作:在 2025 年 1 月 21 日之前使用此 API,或更快地迁移到 API v2 GA。
目标:从 2025 年 1 月 21 日起检索当前和以前的计费周期的未计费每日使用行项。
操作:仅使用 API v2 GA。
若要无缝过渡到新 API,请遵循以下链接:计费和未计费的每日分级使用情况对帐 API v2 (GA)。
感谢你的注意,我们期待着你继续成功使用我们的计费 API。
如何获取未计费的商业消费行项详细信息的集合。
可以使用以下方法以编程方式获取未计费的商业使用行项(也称为开放使用行项)的详细信息集合。
重要
每日分级使用情况数据不包括这些产品的费用:
- Azure 预留
- Azure 节省计划
- Office
- Dynamics
- Microsoft Power Apps
- 永久性软件
- 软件订阅
- 非Microsoft或市场 SaaS 产品
注意
可以通过 API 或合作伙伴中心门户访问 未计费 的每日分级使用情况行项。 为了确保准确的数据,最多允许 24 小时的可用性。 根据你的位置以及计量报告使用情况的时间,可能会有进一步的延迟。
我们首先确定每日按计费使用情况数据的时间交付的优先级。 有时,在前一个月的计费使用情况数据可用之前,可能不会看到最近 未计费 的每日使用量数据。 收到计费使用情况数据后,可以从本月初检索所有更新的未计费使用情况数据。
由于我们努力提供最准确、最及时的信息,你对你的理解和耐心是值得赞赏的。
先决条件
- 合作伙伴中心身份验证中所述的凭据。 此方案支持使用独立应用和 App+User 凭据进行身份验证。
C#
若要获取指定发票的行项,请执行以下操作:
发票对象包含指定发票的所有信息。 提供程序标识未计费的详细信息的来源(例如 OneTime)。 InvoiceLineItemType 指定类型(例如 UsageLineItem)。
以下示例代码使用 foreach 循环来处理 InvoiceLineItems 集合。 为每个 InvoiceLineItemType 检索单独的行项集合。
获取对应于 InvoiceDetail 实例的行项集合:
- 将实例的 BillingProvider 和 InvoiceLineItemType 传递给 By 方法。
- 调用 Get 或 GetAsync 方法以检索关联的行项。
- 创建枚举器以遍历集合,如以下示例所示。
// IAggregatePartner partnerOperations;
// 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("unbilled").By("onetime", "usagelineitems", curencyCode, period, pageMaxSizeReconLineItems).Get();
var fetchNext = true;
ConsoleKeyInfo keyInfo;
var itemNumber = 1;
while (fetchNext)
{
Console.Out.WriteLine("\tLine 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("unbilled").By("onetime", "usagelineitems", curencyCode, period, pageMaxSizeReconLineItems).Seek(seekBasedResourceCollection.ContinuationToken, SeekOperation.Next);
}
}
}
有关类似示例,请参阅:
- 示例: 控制台测试应用
- 项目: 合作伙伴中心 SDK 示例
- 类: GetUnBilledConsumptionReconLineItemsPaging.cs
REST 请求
请求语法
可以根据用例对 REST 请求使用以下语法。 有关详细信息,请参阅每个语法的说明。
方法 | 请求 URI | 语法用例说明 |
---|---|---|
GET | {baseURL}/v1/invoices/unbilled/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&period={period} HTTP/1.1 | 使用此语法可返回给定发票的每个行项的完整列表。 |
GET | {baseURL}/v1/invoices/unbilled/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&period={period}&size={size} HTTP/1.1 | 将此语法用于大型发票。 将此语法与指定的大小和基于 0 的偏移量一起使用,以返回分页的行项列表。 |
GET | {baseURL}/v1/invoices/unbilled/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&period={period}&size={size}&seekOperation=Next | 使用此语法获取下一页对帐行项。seekOperation = "Next" |
URI 参数
创建请求时,请使用以下 URI 和查询参数。
名称 | 类型 | 必需 | 说明 |
---|---|---|---|
提供程序 | string | 是 | 提供程序:“OneTime”。 |
invoice-line-item-type | string | 是 | 发票详细信息的类型:“UsageLineItems”、“UsageLineItems”。 |
currencyCode | string | 是 | 未计费行项的货币代码。 |
period | string | 是 | 未计费的重新计费周期(例如: 当前、 上一个)。 假设需要在 1 月份查询计费周期(2020/01/01 -2020 年 1 月 31 日)的未计费使用情况数据,请选择时间段作为“当前”,否则为“上一个”。 |
size | 数字 | 否 | 要返回的最多项目数。 默认大小为 2000。 |
seekOperation | string | 否 | 设置为 seekOperation=Next 获取对帐行项的下一页。 |
请求标头
有关详细信息,请参阅合作伙伴中心 REST 标头。
请求正文
无。
REST 响应
如果成功,响应将包含行项详细信息的集合。
对于行项 ChargeType,“购买”值将映射到“新建”,值“退款”将映射到“取消”。
响应的成功和错误代码
每个响应都有一个 HTTP 状态代码,指示成功或失败和其他调试信息。 使用网络跟踪工具读取此代码、错误类型和其他参数。 如需完整列表,请参阅合作伙伴中心 REST 错误代码。
请求-响应示例
请求-响应示例 1
以下详细信息适用于此示例:
- 提供程序: OneTime
- InvoiceLineItemType: UsageLineItems
- 句点:上一个
请求示例 1
GET https://api.partnercenter.microsoft.com/v1//invoices/unbilled/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": "00083575-bbd0-54de-b2ad-0f5b0e927d71",
"partnerName": "MTBC",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "VM-Series Next-Generation Firewall (Bundle 2 PAYG)",
"productName": "VM-Series Next Generation Firewall",
"publisherName": "Test Alto Networks, Inc.",
"publisherId": "",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Pay-As-You-Go",
"chargeStartDate": "2019-01-01T00:00:00Z",
"chargeEndDate": "2019-02-01T00:00:00Z",
"usageDate": "2019-01-01T00:00:00Z",
"meterType": "1 Compute Hour - 4core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "4core",
"meterSubCategory": "VM-Series Next Generation Firewall",
"meterName": "VM-Series Next Generation Firewall - VM-Series Next-Generation Firewall (Bundle 2 PAYG) - 4 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS",
"consumedService": "Microsoft.Compute",
"resourceGroup": "ECH-PAN-RG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ECH-PAN-RG/providers/Microsoft.Compute/virtualMachines/echpanfw",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_D3_v2\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "",
"unitPrice": 1.2799888920023,
"quantity": 24.0,
"unitType": "",
"billingPreTaxTotal": 30.7197334080551,
"billingCurrency": "USD",
"pricingPreTaxTotal": 30.7197334080551,
"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": "00083575-bbd0-54de-b2ad-0f5b0e927d71",
"partnerName": "MTBC",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "VM-Series Next-Generation Firewall (Bundle 2 PAYG)",
"productName": "VM-Series Next Generation Firewall",
"publisherName": "Test Alto Networks, Inc.",
"publisherId": "",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Pay-As-You-Go",
"chargeStartDate": "2019-01-01T00:00:00Z",
"chargeEndDate": "2019-02-01T00:00:00Z",
"usageDate": "2019-01-02T00:00:00Z",
"meterType": "1 Compute Hour - 4core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "4core",
"meterSubCategory": "VM-Series Next Generation Firewall",
"meterName": "VM-Series Next Generation Firewall - VM-Series Next-Generation Firewall (Bundle 2 PAYG) - 4 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS",
"consumedService": "Microsoft.Compute",
"resourceGroup": "ECH-PAN-RG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ECH-PAN-RG/providers/Microsoft.Compute/virtualMachines/echpanfw",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_D3_v2\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "",
"unitPrice": 1.2799888920023,
"quantity": 24.0,
"unitType": "",
"billingPreTaxTotal": 30.7197334080551,
"billingCurrency": "USD",
"pricingPreTaxTotal": 30.7197334080551,
"pricingCurrency": "USD",
"entitlementId": "31cdf47f-b249-4edd-9319-637862d12345",
"entitlementDescription": "Partner Subscription",
"pcToBCExchangeRate": 1,
"pcToBCExchangeRateDate": "2019-08-01T00:00:00Z",
"effectiveUnitPrice": 0,
"rateOfPartnerEarnedCredit": 0,
"rateOfCredit": 1,
"creditType": "Azure Credit Applied",
"invoiceLineItemTypce": "usage_line_items",
"billingProvider": "marketplace",
"benefitOrderId": "",
"benefitId": "",
"benefitType": "Charge",
"attributes": {
"objectType": "DailyRatedUsageLineItem"
}
}
],
"links": {
"self": {
"uri": "/invoices/unbilled/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000",
"method": "GET",
"headers": []
},
"next": {
"uri": "/invoices/unbilled/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
以下详细信息适用于此示例:
- 提供程序: OneTime
- InvoiceLineItemType: UsageLineItems
- 句点:上一个
- SeekOperation: 下一步
请求示例 2
GET https://api.partnercenter.microsoft.com/v1/invoices/unbilled/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": "00083575-bbd0-54de-b2ad-0f5b0e927d71",
"partnerName": "MTBC",
"customerId": "",
"customerName": "",
"customerDomainName": "",
"invoiceNumber": "",
"productId": "",
"skuId": "",
"availabilityId": "",
"skuName": "VM-Series Next-Generation Firewall (Bundle 2 PAYG)",
"productName": "VM-Series Next Generation Firewall",
"publisherName": "Test Alto Networks, Inc.",
"publisherId": "",
"subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
"subscriptionDescription": "Pay-As-You-Go",
"chargeStartDate": "2019-01-01T00:00:00Z",
"chargeEndDate": "2019-02-01T00:00:00Z",
"usageDate": "2019-01-02T00:00:00Z",
"meterType": "1 Compute Hour - 4core",
"meterCategory": "Virtual Machine Licenses",
"meterId": "4core",
"meterSubCategory": "VM-Series Next Generation Firewall",
"meterName": "VM-Series Next Generation Firewall - VM-Series Next-Generation Firewall (Bundle 2 PAYG) - 4 Core Hours",
"meterRegion": "",
"unitOfMeasure": "1 Hour",
"resourceLocation": "EASTUS",
"consumedService": "Microsoft.Compute",
"resourceGroup": "ECH-PAN-RG",
"resourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ECH-PAN-RG/providers/Microsoft.Compute/virtualMachines/echpanfw",
"tags": "",
"additionalInfo": "{ \"ImageType\": null, \"ServiceType\": \"Standard_D3_v2\", \"VMName\": null, \"VMProperties\": null, \"UsageType\": \"ComputeHR_SW\"}",
"serviceInfo1": "",
"serviceInfo2": "",
"customerCountry": "",
"mpnId": "1234567",
"resellerMpnId": "",
"chargeType": "",
"unitPrice": 1.2799888920023,
"quantity": 24.0,
"unitType": "",
"billingPreTaxTotal": 30.7197334080551,
"billingCurrency": "USD",
"pricingPreTaxTotal": 30.7197334080551,
"pricingCurrency": "USD",
"entitlementId": "31cdf47f-b249-4edd-9319-637862d8c0b4",
"entitlementDescription": "Partner Subscription",
"pcToBCExchangeRate": 1,
"pcToBCExchangeRateDate": "2019-08-01T00:00:00Z",
"effectiveUnitPrice": 0,
"rateOfPartnerEarnedCredit": 0.15,
"rateOfCredit": 0.15,
"creditType": "Partner Earned Credit Applied",
"invoiceLineItemType": "usage_line_items",
"billingProvider": "marketplace",
"benefitOrderId": "",
"benefitId": "",
"benefitType": "Charge",
"attributes": {
"objectType": "DailyRatedUsageLineItem"
}
}
],
"links": {
"self": {
"uri": "/invoices/unbilled/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode=usd&period=previous&size=2000",
"method": "GET",
"headers": []
}
},
"attributes": {
"objectType": "Collection"
}
}