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": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"aggregation_type": "sum_agg",
"recurring": false,
"field_name": "gb",
"weighted_interval": "seconds",
"filters": [
{
"key": "provider",
"values": ["us-east-1", "us-east-2", "eu-west-1"]
}
]
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import BillableMetricFilter, BillableMetric
client = Client(api_key='__YOUR_API_KEY__')
filter = BillableMetricFilter(
key='region',
values=['us-east-1', 'us-east-2', 'eu-west-1']
)
billable_metric = BillableMetric(
name='Storage',
code='storage',
description='GB of storage used in my application',
aggregation_type='sum_agg',
recurring=false,
field_name='gb',
weighted_interval= 'seconds',
filters=[filter]
)
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: 'Storage',
code: 'storage',
description: 'GB of storage used in my application',
aggregation_type: 'sum_agg',
recurring: false,
field_name: 'gb',
weighted_interval: 'seconds',
filters: [
{
key: 'region',
values: %w[us-east-1 us-east-2 eu-west-1]
}
]
}, 'code')
const newBillableMetricObject = {
name: "Storage",
code: "storage",
recurring: false,
aggregation_type: "sum_agg",
weighted_interval: "seconds",
field_name: "gb",
};
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: "Storage",
Code: "storage",
Description: "GB of storage used in my application"
AggregationType: lago.SumAggregation,
FieldName: "gb",
Recurring: false,
WeightedInterval: "seconds",
Filters: [1]map[string]interface{}{
"key": "region",
"values": [3]string{"us-east-1", "us-east-2", "eu-west-1"},
},
}
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;
}