Update Billable metric
Route
PUT
/api/v1/billable_metrics/:code
Usage
- Curl
- Python
- Ruby
- Javascript
- Go
- C#
- PHP
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request PUT "$LAGO_URL/api/v1/billable_metrics/:code" \
--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"]
}
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import BillableMetric
client = Client(api_key='__YOUR_API_KEY__')
billable_metric = BillableMetric(
name='name',
code='code_first',
description='desc',
aggregation_type='sum_agg',
field_name='amount_sum'
)
try:
client.billable_metrics.update(billable_metric, 'code')
except LagoApiError as e:
repair_broken_state(e) # do something on error or raise your own exception
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})
client.billable_metrics.update({
name: 'BM1',
code: 'code_bm',
description: 'description',
aggregation_type: 'sum_agg',
field_name: 'amount_sum',
}, 'code')
const newBillableMetricObject = {
name: "name1",
code: "code1",
aggregationType: "sum_agg",
fieldName: "field_name",
};
await client.billableMetrics.updateBillableMetric("code", {
billableMetric: newBillableMetricObject,
});
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
lagoClient := lago.New().
SetApiKey("__YOUR_API_KEY__")
bmInput := &lago.BillableMetricInput{
Name: "First Billable Metric",
Code: "first_bm",
Description: "My First Billable Metric"
AggregationType: lago.CountAggregation,
FieldName: "sum",
}
billableMetric, err := lagoClient.BillableMetric().Update(bmInput)
if err != nil {
// Error is *lago.Error
panic(err)
}
// billableMetric is *lago.BillableMetric
fmt.Println(billableMetric)
}
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class UpdateBillableMetricExample
{
public static void Main()
{
Configuration.Default.BasePath = "https://api.getlago.com/api/v1";
// Configure HTTP bearer authorization: bearerAuth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new BillableMetricsApi(Configuration.Default);
var code = "example_code"; // string | Code of the existing billable metric
var billableMetricInput = new BillableMetricInput(); // BillableMetricInput | Update an existing billable metric
try
{
// Update an existing billable metric
BillableMetric result = apiInstance.UpdateBillableMetric(code, billableMetricInput);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling BillableMetricsApi.UpdateBillableMetric: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: bearerAuth
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new OpenAPI\Client\Api\BillableMetricsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$code = "example_code"; // string | Code of the existing billable metric
$billable_metric_input = new \OpenAPI\Client\Model\BillableMetricInput(); // \OpenAPI\Client\Model\BillableMetricInput | Update an existing billable metric
try {
$result = $apiInstance->updateBillableMetric($code, $billable_metric_input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling BillableMetricsApi->updateBillableMetric: ', $e->getMessage(), PHP_EOL;
}
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"]
}
}
}
Attributes | Type | Description |
---|---|---|
name | String Optional | Billable metric name. |
code | String Optional | Code identifying the billable metric. It won't be updated if billable metric is attached to any subscriptions |
description | String Optional | Description of the billable metric |
aggregation_type | String Optional | Aggregation 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)It won't be updated if billable metric is attached to any subscriptions |
field_name | String Optional | Field name used in events. It won't be updated if billable metric is attached to any subscriptions |
group | Object Optional | Group (one or two dimensions) for pricing differently the billable metric |
Group - One dimension
Attributes | Type | Description |
---|---|---|
key | String Required | Name of the event's field used for grouping |
values | Array Required | Array of string representing all possible values |
Example:
{
"group": {
"key": "country",
"values": ["france", "italy", "spain"]
}
}
Group - Two dimensions
Attributes | Type | Description |
---|---|---|
key | String Required | Name of the first event's field used for grouping |
values | Array Required | Array of objects representing all possible values |
Values:
Attributes | Type | Description |
---|---|---|
name | String Required | Value for the first dimension of the group |
key | Array Required | Name of the second event's field used for grouping |
values | Array Required | Array 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
- HTTP 200
- HTTP 400
- HTTP 401
- HTTP 404
- HTTP 422
The billable metric was successfully updated
Returns an billable metric object.
{
"status": 400,
"error": "Bad Request"
}
The billable_metric
json root is not present in the request body.
{
"status": 401,
"error": "Unauthorized"
}
Access to the API endpoint is unhautorized.
Possible reasons are:
- The
Authorization
header is missing - The
Authorization
header does not contain the API key - The Api key is invalid or expired
{
"status": 404,
"error": "Not Found",
"code": "billable_metric_not_found"
}
The billable_metric
was not found.
{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {
"field": ["error"]
}
}
Possible errors:
Field | Code | Description |
---|---|---|
name | value_is_mandatory | name value is missing |
code | value_is_mandatory | code value is missing |
code | value_already_exists | code value is already used for another billable metric |
field_name | value_is_mandatory | field_name value is missing |
aggregation_type | value_is_invalid | Provided aggregation_type value is invalid |
group | value_is_invalid | Format of provided JSON for group is invalid |