Skip to main content

Create billable metric

Route

POST
/api/v1/billable_metrics

Usage

LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"

curl --location --request POST "$LAGO_URL/api/v1/billable_metrics" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"billable_metric": {
"name": "bm_name",
"code": "bm_code",
"description": "description",
"aggregation_type": "sum_agg",
"field_name": "amount_sum",
"group": {
"key": "region",
"value": ["USA", "EUROPE"]
}
}
}'

Arguments

{
"billable_metric": {
"name": "bm_name",
"code": "bm_code",
"description": "description",
"aggregation_type": "sum_agg",
"field_name": "amount_sum",
"group": {
"key": "country",
"values": ["france", "italy", "spain"]
}
}
}
AttributesTypeDescription
nameString      RequiredBillable metric name
codeString      RequiredCode identifying the billable metric
descriptionString      OptionalDescription of the billable metric
aggregation_typeString      RequiredAggregation type that is used in event calculations.
It can be count_agg (metered), sum_agg (metered), max_agg (metered), unique_count_agg (metered) or recurring_count_agg (persistent)
field_nameString      Required (optional only for count_agg aggregation type)Field name used in events.
groupObject      OptionalGroup (one or two dimensions) for pricing differently the billable metric

Group - One dimension

AttributesTypeDescription
keyString      RequiredName of the event's field used for grouping
valuesArray      RequiredArray of string representing all possible values

Example:

{
"group": {
"key": "country",
"values": ["france", "italy", "spain"]
}
}

Group - Two dimensions

AttributesTypeDescription
keyString      RequiredName of the first event's field used for grouping
valuesArray      RequiredArray of objects representing all possible values

Values:

AttributesTypeDescription
nameString      RequiredValue for the first dimension of the group
keyArray      RequiredName of the second event's field used for grouping
valuesArray      RequiredArray of string representing all possible values of the second dimension

Example:

{
"group": {
"key": "cloud",
"values": [
{
"name": "AWS",
"key": "region",
"values": ["USA", "EUROPE"]
}, {
"name": "Google",
"key": "region",
"values": ["USA"]
}
]
}
}

Responses

The billable metric was created

Returns a billable metric object.