curl --request POST \
--url https://api.metronome.com/v1/customers/{customer_id}/previewEvents \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"event_type": "heartbeat",
"timestamp": "2021-01-01T00:00:00Z",
"properties": {
"cpu_hours": 100,
"memory_gb_hours": 200
}
}
],
"mode": "replace"
}
'{
"data": [
{
"id": "6a37bb88-8538-48c5-b37b-a41c836328bd",
"customer_id": "617e39d8-68f4-4592-b8d2-c2bf26a76989",
"type": "USAGE",
"start_timestamp": "2021-01-01T00:00:00Z",
"end_timestamp": "2021-02-01T00:00:00Z",
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"contract_id": "9de042a1-b955-43ce-9ab4-e3c2004570d1",
"line_items": [
{
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"name": "CPU hours",
"quantity": 31416,
"total": 62832,
"type": "usage",
"product_id": "5c1f40cd-9ff8-4e90-ae53-5f81b0e9d1e8"
}
],
"total": 62832,
"status": "DRAFT"
},
{
"id": "9543ee18-7bed-4b72-9797-729758093cf1",
"customer_id": "617e39d8-68f4-4592-b8d2-c2bf26a76989",
"type": "USAGE",
"start_timestamp": "2021-01-01T00:00:00Z",
"end_timestamp": "2021-02-01T00:00:00Z",
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"contract_id": "cb3b77c4-467c-418a-ab68-a08113760cd2",
"line_items": [
{
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"name": "Storage GB-hours",
"quantity": 15708,
"total": 31416,
"type": "usage",
"product_id": "7ba25fb0-33b0-4dc8-911e-4b4065ed585e"
}
],
"total": 31416,
"status": "DRAFT"
}
]
}Preview how a set of events will affect a customer’s invoices. Generates draft invoices for a customer using their current contract configuration and the provided events. This is useful for testing how new events will affect the customer’s invoices before they are actually processed. Customers on contracts with SQL billable metrics are not supported.
curl --request POST \
--url https://api.metronome.com/v1/customers/{customer_id}/previewEvents \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"events": [
{
"event_type": "heartbeat",
"timestamp": "2021-01-01T00:00:00Z",
"properties": {
"cpu_hours": 100,
"memory_gb_hours": 200
}
}
],
"mode": "replace"
}
'{
"data": [
{
"id": "6a37bb88-8538-48c5-b37b-a41c836328bd",
"customer_id": "617e39d8-68f4-4592-b8d2-c2bf26a76989",
"type": "USAGE",
"start_timestamp": "2021-01-01T00:00:00Z",
"end_timestamp": "2021-02-01T00:00:00Z",
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"contract_id": "9de042a1-b955-43ce-9ab4-e3c2004570d1",
"line_items": [
{
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"name": "CPU hours",
"quantity": 31416,
"total": 62832,
"type": "usage",
"product_id": "5c1f40cd-9ff8-4e90-ae53-5f81b0e9d1e8"
}
],
"total": 62832,
"status": "DRAFT"
},
{
"id": "9543ee18-7bed-4b72-9797-729758093cf1",
"customer_id": "617e39d8-68f4-4592-b8d2-c2bf26a76989",
"type": "USAGE",
"start_timestamp": "2021-01-01T00:00:00Z",
"end_timestamp": "2021-02-01T00:00:00Z",
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"contract_id": "cb3b77c4-467c-418a-ab68-a08113760cd2",
"line_items": [
{
"credit_type": {
"id": "2714e483-4ff1-48e4-9e25-ac732e8f24f2",
"name": "USD (cents)"
},
"name": "Storage GB-hours",
"quantity": 15708,
"total": 31416,
"type": "usage",
"product_id": "7ba25fb0-33b0-4dc8-911e-4b4065ed585e"
}
],
"total": 31416,
"status": "DRAFT"
}
]
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
The events to preview
Array of usage events to include in the preview calculation. Must contain at least one event in merge mode.
1 - 100 elementsShow child attributes
1RFC 3339 formatted. If not provided, the current time will be used.
Optional unique identifier for event deduplication. When provided, preview events are automatically deduplicated against historical events from the past 34 days. Duplicate transaction IDs within the same request will return an error.
1 - 128Controls how the provided events are combined with existing usage data. Use replace to calculate the preview as if these are the only events for the customer, ignoring all historical usage. Use merge to combine these events with the customer's existing usage. Defaults to replace.
replace, merge When true, line items with zero quantity are excluded from the response.
Success
Show child attributes
Show child attributes
The type of line item.
scheduled: Line item is associated with a scheduled charge. View the scheduled_charge_id on the line item.commit_purchase: Line item is associated with a payment for a prepaid commit. View the commit_id on the line item.usage: Line item is associated with a usage product or composite product. View the product_id on the line item to determine which product.subscription: Line item is associated with a subscription. e.g. monthly recurring payment for an in-advance subscription.applied_commit_or_credit: On metronome invoices, applied commits and credits are associated with their own line items. These line items have negative totals. Use the applied_commit_or_credit object on the line item to understand the id of the applied commit or credit, and its type. Note that the application of a postpaid commit is associated with a line item, but the total on the line item is not included in the invoice's total as postpaid commits are paid in-arrears.cpu_conversion: Line item converting between a custom pricing unit and fiat currency, using the conversion rate set on the rate card. This line item will appear when there are products priced in custom pricing units, and there is insufficient prepaid commit/credit in that custom pricing unit to fully cover the spend. Then, the outstanding spend in custom pricing units will be converted to fiat currency using a cpu_conversion line item.The quantity associated with the line item.
The unit price associated with the line item.
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.
Show child attributes
Default price. For FLAT rate_type, this must be >=0. For PERCENTAGE rate_type, this is a decimal fraction, e.g. use 0.1 for 10%; this must be >=0 and <=1.
Only set for PERCENTAGE rate_type. Defaults to false. If true, rate is computed using list prices rather than the standard rates for this product on the contract.
ID of the product associated with the line item.
The current product tags associated with the line item's product_id.
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.
Indicates whether the line item is prorated for SUBSCRIPTION type product.
The line item's start date (inclusive).
The line item's end date (exclusive).
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.
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.
PrepaidCommit (for commit types PREPAID and CREDIT) or PostpaidCommit (for commit type POSTPAID).
ID of scheduled charge.
ID of the discount applied to this line item.
"DRAFT, VOID, or FINALIZED"
"SCHEDULED or USAGE"
Beginning of the usage period this invoice covers (UTC)
End of the usage period this invoice covers (UTC)
When the invoice was issued (UTC)
When the invoice was created (UTC). This field is present for correction invoices only.
Show child attributes
aws_marketplace, stripe, azure_marketplace, quickbooks_online, metronome DRAFT, FINALIZED, PAID, PARTIALLY_PAID, UNCOLLECTIBLE, VOID, DELETED, PAYMENT_FAILED, INVALID_REQUEST_ERROR, SKIPPED, SENT, QUEUED A URL to the PDF of the invoice, if available from the billing provider.
Tax details for the invoice, if available from the billing provider.
Show child attributes
The total amount invoiced, if available from the billing provider.
The subtotal amount invoiced, if available from the billing provider.
Error message from the billing provider, if available.
The ID of the payment in the external system, if available.