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"
}
'import requests
url = "https://api.metronome.com/v1/customers/{customer_id}/previewEvents"
payload = {
"events": [
{
"event_type": "heartbeat",
"timestamp": "2021-01-01T00:00:00Z",
"properties": {
"cpu_hours": 100,
"memory_gb_hours": 200
}
}
],
"mode": "replace"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
events: [
{
event_type: 'heartbeat',
timestamp: '2021-01-01T00:00:00Z',
properties: {cpu_hours: 100, memory_gb_hours: 200}
}
],
mode: 'replace'
})
};
fetch('https://api.metronome.com/v1/customers/{customer_id}/previewEvents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.metronome.com/v1/customers/{customer_id}/previewEvents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'events' => [
[
'event_type' => 'heartbeat',
'timestamp' => '2021-01-01T00:00:00Z',
'properties' => [
'cpu_hours' => 100,
'memory_gb_hours' => 200
]
]
],
'mode' => 'replace'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.metronome.com/v1/customers/{customer_id}/previewEvents"
payload := strings.NewReader("{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.metronome.com/v1/customers/{customer_id}/previewEvents")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.metronome.com/v1/customers/{customer_id}/previewEvents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}"
response = http.request(request)
puts response.read_body{
"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"
}
]
}{
"message": "<string>"
}{
"message": "<string>"
}Preview events
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"
}
'import requests
url = "https://api.metronome.com/v1/customers/{customer_id}/previewEvents"
payload = {
"events": [
{
"event_type": "heartbeat",
"timestamp": "2021-01-01T00:00:00Z",
"properties": {
"cpu_hours": 100,
"memory_gb_hours": 200
}
}
],
"mode": "replace"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
events: [
{
event_type: 'heartbeat',
timestamp: '2021-01-01T00:00:00Z',
properties: {cpu_hours: 100, memory_gb_hours: 200}
}
],
mode: 'replace'
})
};
fetch('https://api.metronome.com/v1/customers/{customer_id}/previewEvents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.metronome.com/v1/customers/{customer_id}/previewEvents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'events' => [
[
'event_type' => 'heartbeat',
'timestamp' => '2021-01-01T00:00:00Z',
'properties' => [
'cpu_hours' => 100,
'memory_gb_hours' => 200
]
]
],
'mode' => 'replace'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.metronome.com/v1/customers/{customer_id}/previewEvents"
payload := strings.NewReader("{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.metronome.com/v1/customers/{customer_id}/previewEvents")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.metronome.com/v1/customers/{customer_id}/previewEvents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"events\": [\n {\n \"event_type\": \"heartbeat\",\n \"timestamp\": \"2021-01-01T00:00:00Z\",\n \"properties\": {\n \"cpu_hours\": 100,\n \"memory_gb_hours\": 200\n }\n }\n ],\n \"mode\": \"replace\"\n}"
response = http.request(request)
puts response.read_body{
"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"
}
]
}{
"message": "<string>"
}{
"message": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Body
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
Show child attributes
Controls 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.
Response
Success
Show child attributes
Show child attributes