Get invoice billed commercial consumption line items
Note
After January 21, 2025, you can continue using this API but not for every billing periods. Here's how to choose the right version based on your needs:
Goal: Retrieve daily rated usage line items for billing periods from September 2022 to December 2024.
Action: Use this API until January 21, 2025, unless you already switched to API v2 GA.
Goal: Retrieve daily rated usage line items for billing periods before September 2022.
Action: Use this API exclusively.
Goal: Retrieve daily rated usage line items for billing periods from September 2022 onward but only after January 21, 2025.
Action: Use only API v2 GA.
For a seamless transition to the new APIs, follow this link: Billed and unbilled daily rated usage reconciliation API v2 (GA).
Thank you for your attention, and we look forward to your continued success with our billing APIs.
You can use the following methods to get a collection of details for commercial consumption invoice line items (also known as closed daily rated usage line items) for a specified invoice.
Important
The daily rated usage data doesn't include the charges for these products:
- Azure reservation
- Azure savings plan
- Office
- Dynamics
- Microsoft Power Apps
- Perpetual software
- Software subscription
- Non-Microsoft or Marketplace SaaS product
Prerequisites
Credentials as described in Partner Center authentication. This scenario supports authentication with both standalone App and App+User credentials.
The invoice ID to get the line items for.
C#
To get the commercial line items for the specified invoice, you must retrieve the invoice object:
Call the ById method to get an interface to invoice operations for the specified invoice.
Call the Get or GetAsync method to retrieve the invoice object. The invoice object contains all of the information for the specified invoice.
The Provider identifies the source of the billed detail information (for example, onetime). The InvoiceLineItemType specifies the type (for example, UsageLineItem).
The following example code uses a foreach loop to process the line items collection. A separate collection of line items is retrieved for each InvoiceLineItemType.
To get a collection of line items that correspond to an InvoiceDetail instance:
Pass the instance's BillingProvider and InvoiceLineItemType to the By method.
Call the Get or GetAsync method to retrieve the associated line items.
Create an enumerator to traverse the collection as shown in the following example.
// 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);
}
}
}
See an example:
- Sample: Console test app
- Project: Partner Center SDK Samples
- Class: GetBilledConsumptionReconLineItemsPaging.cs
REST request
Request syntax
Use the first syntax to return a full list of every line item for the given invoice. For large invoices, use the second syntax with a specified size and 0-based offset to return a paged list of line items. Use the third syntax to get the next page of recon line items using seekOperation = "Next"
.
Method | Request URI |
---|---|
GET | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode} HTTP/1.1 |
GET | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&size={size} HTTP/1.1 |
GET | {baseURL}/v1/invoices/{invoice-id}/lineitems?provider=onetime&invoicelineitemtype=usagelineitems¤cycode={currencycode}&size={size}&seekOperation=Next |
URI parameters
Use the following URI and query parameters when creating the request.
Name | Type | Required | Description |
---|---|---|---|
invoice-id | string | Yes | A string that identifies the invoice. |
provider | string | Yes | The provider: "OneTime". |
invoice-line-item-type | string | Yes | The type of invoice detail: "UsageLineItems". |
currencyCode | string | Yes | The currency code for the billed line items. |
period | string | Yes | The period for billed recon. example: current, previous. |
size | number | No | The maximum number of items to return. Default size is 2000 |
seekOperation | string | No | Set seekOperation=Next to get the next page of recon line items. |
Request headers
For more information, see Partner Center REST headers.
Request body
None.
REST response
If successful, the response contains the collection of line item details.
For the line item ChargeType, the value Purchase is mapped to New. The value Refund is mapped to Cancel.
Response success and error codes
Each response comes with an HTTP status code that indicates success or failure and other debugging information. Use a network trace tool to read this code, error type, and more parameters. For the full list, see Partner Center REST error codes.
REST examples
Request-response example 1
The details for this example REST request and response are as follows:
- Provider: OneTime
- InvoiceLineItemType: UsageLineItems
- Period: Previous
Request example 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
Important
As of June 2023, the latest Partner Center .NET SDK release 3.4.0 is now archived. You can download the SDK release from GitHub, along with a readme file that contains useful information.
Partners are encouraged to continue to use the Partner Center REST APIs.
Response example 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"
}
}
Request-response example 2
The details for this example REST request and response are as follows:
- Provider: OneTime
- InvoiceLineItemType: UsageLineItems
- Period: Previous
- SeekOperation: Next
Request example 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
Response example 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"
}
}