## Create Historical Invoices `v1.contracts.create_historical_invoices(ContractCreateHistoricalInvoicesParams**kwargs) -> ContractCreateHistoricalInvoicesResponse` **post** `/v1/contracts/createHistoricalInvoices` Creates historical usage invoices for a contract ### Parameters - **invoices:** `Iterable[Invoice]` - **contract\_id:** `str` - **credit\_type\_id:** `str` - **customer\_id:** `str` - **exclusive\_end\_date:** `Union[str, datetime]` - **inclusive\_start\_date:** `Union[str, datetime]` - **issue\_date:** `Union[str, datetime]` - **usage\_line\_items:** `Iterable[InvoiceUsageLineItem]` - **exclusive\_end\_date:** `Union[str, datetime]` - **inclusive\_start\_date:** `Union[str, datetime]` - **product\_id:** `str` - **presentation\_group\_values:** `Dict[str, str]` - **pricing\_group\_values:** `Dict[str, str]` - **quantity:** `float` - **subtotals\_with\_quantity:** `Iterable[InvoiceUsageLineItemSubtotalsWithQuantity]` - **exclusive\_end\_date:** `Union[str, datetime]` - **inclusive\_start\_date:** `Union[str, datetime]` - **quantity:** `float` - **billable\_status:** `Literal["billable", "unbillable"]` This field's availability is dependent on your client's configuration. - `"billable"` - `"unbillable"` - **breakdown\_granularity:** `Literal["HOUR", "DAY"]` - `"HOUR"` - `"DAY"` - **custom\_fields:** `Dict[str, str]` - **preview:** `bool` ### Returns - `class ContractCreateHistoricalInvoicesResponse` - **data:** `List[Invoice]` - **id:** `str` - **credit\_type:** `CreditTypeData` - **customer\_id:** `str` - **line\_items:** `List[LineItem]` - **credit\_type:** `CreditTypeData` - **name:** `str` - **total:** `float` - **applied\_commit\_or\_credit:** `Optional[LineItemAppliedCommitOrCredit]` Details about the credit or commit that was applied to this line item. Only present on line items with product of `USAGE`, `SUBSCRIPTION` or `COMPOSITE` types. - **id:** `str` - **type:** `Literal["PREPAID", "POSTPAID", "CREDIT"]` - `"PREPAID"` - `"POSTPAID"` - `"CREDIT"` - **commit\_custom\_fields:** `Optional[Dict[str, str]]` - **commit\_id:** `Optional[str]` For line items with product of `USAGE`, `SUBSCRIPTION`, or `COMPOSITE` types, the ID of the credit or commit that was applied to this line item. For line items with product type of `FIXED`, the ID of the prepaid or postpaid commit that is being paid for. - **commit\_netsuite\_item\_id:** `Optional[str]` - **commit\_netsuite\_sales\_order\_id:** `Optional[str]` - **commit\_segment\_id:** `Optional[str]` - **commit\_type:** `Optional[str]` `PrepaidCommit` (for commit types `PREPAID` and `CREDIT`) or `PostpaidCommit` (for commit type `POSTPAID`). - **custom\_fields:** `Optional[Dict[str, str]]` - **discount\_custom\_fields:** `Optional[Dict[str, str]]` - **discount\_id:** `Optional[str]` ID of the discount applied to this line item. - **ending\_before:** `Optional[datetime]` The line item's end date (exclusive). - **group\_key:** `Optional[str]` - **group\_value:** `Optional[str]` - **is\_prorated:** `Optional[bool]` Indicates whether the line item is prorated for `SUBSCRIPTION` type product. - **list\_price:** `Optional[Rate]` Only present for contract invoices and when the `include_list_prices` query parameter is set to true. This will include the list rate for the charge if applicable. Only present for usage and subscription line items. - **metadata:** `Optional[str]` - **netsuite\_invoice\_billing\_end:** `Optional[datetime]` The end date for the billing period on the invoice. - **netsuite\_invoice\_billing\_start:** `Optional[datetime]` The start date for the billing period on the invoice. - **netsuite\_item\_id:** `Optional[str]` - **postpaid\_commit:** `Optional[LineItemPostpaidCommit]` Only present for line items paying for a postpaid commit true-up. - **id:** `str` - **presentation\_group\_values:** `Optional[Dict[str, Optional[str]]]` Includes the presentation group values associated with this line item if presentation group keys are used. - **pricing\_group\_values:** `Optional[Dict[str, str]]` Includes the pricing group values associated with this line item if dimensional pricing is used. - **product\_custom\_fields:** `Optional[Dict[str, str]]` - **product\_id:** `Optional[str]` ID of the product associated with the line item. - **product\_tags:** `Optional[List[str]]` The current product tags associated with the line item's `product_id`. - **product\_type:** `Optional[str]` The type of the line item's product. Possible values are `FixedProductListItem` (for `FIXED` type products), `UsageProductListItem` (for `USAGE` type products), `SubscriptionProductListItem` (for `SUBSCRIPTION` type products) or `CompositeProductListItem` (for `COMPOSITE` type products). For scheduled charges, commit and credit payments, the value is `FixedProductListItem`. - **professional\_service\_custom\_fields:** `Optional[Dict[str, str]]` - **professional\_service\_id:** `Optional[str]` - **quantity:** `Optional[float]` The quantity associated with the line item. - **reseller\_type:** `Optional[Literal["AWS", "AWS_PRO_SERVICE", "GCP", "GCP_PRO_SERVICE"]]` - `"AWS"` - `"AWS_PRO_SERVICE"` - `"GCP"` - `"GCP_PRO_SERVICE"` - **scheduled\_charge\_custom\_fields:** `Optional[Dict[str, str]]` - **scheduled\_charge\_id:** `Optional[str]` ID of scheduled charge. - **starting\_at:** `Optional[datetime]` The line item's start date (inclusive). - **sub\_line\_items:** `Optional[List[LineItemSubLineItem]]` - **custom\_fields:** `Dict[str, str]` - **name:** `str` - **quantity:** `float` - **subtotal:** `float` - **charge\_id:** `Optional[str]` - **credit\_grant\_id:** `Optional[str]` - **end\_date:** `Optional[datetime]` The end date for the charge (for seats charges only). - **price:** `Optional[float]` the unit price for this charge, present only if the charge is not tiered and the quantity is nonzero - **start\_date:** `Optional[datetime]` The start date for the charge (for seats charges only). - **tier\_period:** `Optional[LineItemSubLineItemTierPeriod]` when the current tier started and ends (for tiered charges only) - **starting\_at:** `datetime` - **ending\_before:** `Optional[datetime]` - **tiers:** `Optional[List[LineItemSubLineItemTier]]` - **price:** `float` - **quantity:** `float` - **starting\_at:** `float` at what metric amount this tier begins - **subtotal:** `float` - **subscription\_custom\_fields:** `Optional[Dict[str, str]]` - **tier:** `Optional[LineItemTier]` Populated if the line item has a tiered price. - **level:** `float` - **starting\_at:** `str` - **size:** `Optional[str]` - **unit\_price:** `Optional[float]` The unit price associated with the line item. - **status:** `str` - **total:** `float` - **type:** `str` - **amendment\_id:** `Optional[str]` - **billable\_status:** `Optional[Literal["billable", "unbillable"]]` This field's availability is dependent on your client's configuration. - `"billable"` - `"unbillable"` - **contract\_custom\_fields:** `Optional[Dict[str, str]]` - **contract\_id:** `Optional[str]` - **correction\_record:** `Optional[CorrectionRecord]` - **corrected\_invoice\_id:** `str` - **memo:** `str` - **reason:** `str` - **corrected\_external\_invoice:** `Optional[CorrectionRecordCorrectedExternalInvoice]` - **billing\_provider\_type:** `Literal["aws_marketplace", "stripe", "netsuite", 5 more]` - `"aws_marketplace"` - `"stripe"` - `"netsuite"` - `"custom"` - `"azure_marketplace"` - `"quickbooks_online"` - `"workday"` - `"gcp_marketplace"` - **external\_status:** `Optional[Literal["DRAFT", "FINALIZED", "PAID", 8 more]]` - `"DRAFT"` - `"FINALIZED"` - `"PAID"` - `"UNCOLLECTIBLE"` - `"VOID"` - `"DELETED"` - `"PAYMENT_FAILED"` - `"INVALID_REQUEST_ERROR"` - `"SKIPPED"` - `"SENT"` - `"QUEUED"` - **invoice\_id:** `Optional[str]` - **issued\_at\_timestamp:** `Optional[datetime]` - **created\_at:** `Optional[datetime]` When the invoice was created (UTC). This field is present for correction invoices only. - **custom\_fields:** `Optional[Dict[str, object]]` - **customer\_custom\_fields:** `Optional[Dict[str, str]]` - **end\_timestamp:** `Optional[datetime]` End of the usage period this invoice covers (UTC) - **external\_invoice:** `Optional[ExternalInvoice]` - **billing\_provider\_type:** `Literal["aws_marketplace", "stripe", "netsuite", 5 more]` - `"aws_marketplace"` - `"stripe"` - `"netsuite"` - `"custom"` - `"azure_marketplace"` - `"quickbooks_online"` - `"workday"` - `"gcp_marketplace"` - **external\_status:** `Optional[Literal["DRAFT", "FINALIZED", "PAID", 8 more]]` - `"DRAFT"` - `"FINALIZED"` - `"PAID"` - `"UNCOLLECTIBLE"` - `"VOID"` - `"DELETED"` - `"PAYMENT_FAILED"` - `"INVALID_REQUEST_ERROR"` - `"SKIPPED"` - `"SENT"` - `"QUEUED"` - **invoice\_id:** `Optional[str]` - **issued\_at\_timestamp:** `Optional[datetime]` - **invoice\_adjustments:** `Optional[List[InvoiceAdjustment]]` - **credit\_type:** `CreditTypeData` - **name:** `str` - **total:** `float` - **credit\_grant\_custom\_fields:** `Optional[Dict[str, str]]` - **credit\_grant\_id:** `Optional[str]` - **issued\_at:** `Optional[datetime]` When the invoice was issued (UTC) - **net\_payment\_terms\_days:** `Optional[float]` - **netsuite\_sales\_order\_id:** `Optional[str]` This field's availability is dependent on your client's configuration. - **plan\_custom\_fields:** `Optional[Dict[str, str]]` - **plan\_id:** `Optional[str]` - **plan\_name:** `Optional[str]` - **reseller\_royalty:** `Optional[ResellerRoyalty]` Only present for contract invoices with reseller royalties. - **fraction:** `str` - **netsuite\_reseller\_id:** `str` - **reseller\_type:** `Literal["AWS", "AWS_PRO_SERVICE", "GCP", "GCP_PRO_SERVICE"]` - `"AWS"` - `"AWS_PRO_SERVICE"` - `"GCP"` - `"GCP_PRO_SERVICE"` - **aws\_options:** `Optional[ResellerRoyaltyAwsOptions]` - **aws\_account\_number:** `Optional[str]` - **aws\_offer\_id:** `Optional[str]` - **aws\_payer\_reference\_id:** `Optional[str]` - **gcp\_options:** `Optional[ResellerRoyaltyGcpOptions]` - **gcp\_account\_id:** `Optional[str]` - **gcp\_offer\_id:** `Optional[str]` - **salesforce\_opportunity\_id:** `Optional[str]` This field's availability is dependent on your client's configuration. - **start\_timestamp:** `Optional[datetime]` Beginning of the usage period this invoice covers (UTC) - **subtotal:** `Optional[float]` ### Example ```python from datetime import datetime from metronome import Metronome client = Metronome( bearer_token="My Bearer Token", ) response = client.v1.contracts.create_historical_invoices( invoices=[{ "customer_id": "13117714-3f05-48e5-a6e9-a66093f13b4d", "contract_id": "d7abd0cd-4ae9-4db7-8676-e986a4ebd8dc", "credit_type_id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2", "inclusive_start_date": datetime.fromisoformat("2020-01-01T00:00:00.000"), "exclusive_end_date": datetime.fromisoformat("2020-02-01T00:00:00.000"), "issue_date": datetime.fromisoformat("2020-02-01T00:00:00.000"), "usage_line_items": [{ "product_id": "f14d6729-6a44-4b13-9908-9387f1918790", "inclusive_start_date": datetime.fromisoformat("2020-01-01T00:00:00.000"), "exclusive_end_date": datetime.fromisoformat("2020-02-01T00:00:00.000"), "quantity": 100, }], }], preview=False, ) print(response.data) ```