LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/events" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"event": {
"transaction_id": "__UNIQUE_ID__",
"external_subscription_id": "__YOUR_SUBSCRIPTION_ID__",
"code": "__BILLABLE_METRIC_CODE__",
"timestamp": $(date +%s),
"properties": {
"custom_field": 12
}
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import Event
client = Client(api_key='__YOUR_API_KEY__')
event = Event(
transaction_id="__UNIQUE_ID__",
external_subscription_id="__UNIQUE_ID__",
code="__BILLABLE_METRIC_CODE__",
timestamp=1650893379,
properties={"custom_field": "custom"}
)
try:
client.events.create(event)
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.events.create(
transaction_id: "__UNIQUE_ID__",
external_subscription_id: "__SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: Time.now.to_i,
properties: {
custom_field: 12
}
)
await client.events.createEvent({
event: {
transaction_id: "__UNIQUE_TRANSACTION_ID__",
external_subscription_id: "__UNIQUE_SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: 1650893379,
properties: { customField: "custom" },
},
});
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
ctx := context.Background()
lagoClient := lago.New().SetApiKey("__YOUR_API_KEY__")
eventInput := &lago.EventInput{
TransactionID: "__UNIQUE_TRANSACTION_ID__",
ExternalSubscriptionID: "__UNIQUE_SUBSCRIPTION_ID__",
Code: "__BILLABLE_METRIC_CODE__",
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
Properties: map[string]interface{}{
"nbusers": "12",
},
}
res, err := lagoClient.Event().Create(ctx, eventInput)
if err != nil {
// err is *lago.Error
panic(err)
}
// res is *lago.Event
fmt.Println(*res)
}
{
"event": {
"transaction_id": "transaction_1234567890",
"lago_customer_id": null,
"code": "storage",
"timestamp": "2022-04-29T08:59:51.123Z",
"lago_subscription_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"external_subscription_id": "sub_1234567890",
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"precise_total_amount_cents": "1234.56",
"properties": {
"gb": 10
},
"created_at": "2022-04-29T08:59:51Z"
}
}{
"status": 400,
"error": "Bad request"
}{
"status": 401,
"error": "Unauthorized"
}{
"status": 403,
"error": "Forbidden",
"code": "feature_unavailable"
}{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {}
}Events
Send usage event
This endpoint is used for transmitting usage measurement events to either a designated customer or a specific subscription.
POST
/
events
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/events" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"event": {
"transaction_id": "__UNIQUE_ID__",
"external_subscription_id": "__YOUR_SUBSCRIPTION_ID__",
"code": "__BILLABLE_METRIC_CODE__",
"timestamp": $(date +%s),
"properties": {
"custom_field": 12
}
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import Event
client = Client(api_key='__YOUR_API_KEY__')
event = Event(
transaction_id="__UNIQUE_ID__",
external_subscription_id="__UNIQUE_ID__",
code="__BILLABLE_METRIC_CODE__",
timestamp=1650893379,
properties={"custom_field": "custom"}
)
try:
client.events.create(event)
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.events.create(
transaction_id: "__UNIQUE_ID__",
external_subscription_id: "__SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: Time.now.to_i,
properties: {
custom_field: 12
}
)
await client.events.createEvent({
event: {
transaction_id: "__UNIQUE_TRANSACTION_ID__",
external_subscription_id: "__UNIQUE_SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: 1650893379,
properties: { customField: "custom" },
},
});
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
ctx := context.Background()
lagoClient := lago.New().SetApiKey("__YOUR_API_KEY__")
eventInput := &lago.EventInput{
TransactionID: "__UNIQUE_TRANSACTION_ID__",
ExternalSubscriptionID: "__UNIQUE_SUBSCRIPTION_ID__",
Code: "__BILLABLE_METRIC_CODE__",
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
Properties: map[string]interface{}{
"nbusers": "12",
},
}
res, err := lagoClient.Event().Create(ctx, eventInput)
if err != nil {
// err is *lago.Error
panic(err)
}
// res is *lago.Event
fmt.Println(*res)
}
{
"event": {
"transaction_id": "transaction_1234567890",
"lago_customer_id": null,
"code": "storage",
"timestamp": "2022-04-29T08:59:51.123Z",
"lago_subscription_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"external_subscription_id": "sub_1234567890",
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"precise_total_amount_cents": "1234.56",
"properties": {
"gb": 10
},
"created_at": "2022-04-29T08:59:51Z"
}
}{
"status": 400,
"error": "Bad request"
}{
"status": 401,
"error": "Unauthorized"
}{
"status": 403,
"error": "Forbidden",
"code": "feature_unavailable"
}{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {}
}LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/events" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"event": {
"transaction_id": "__UNIQUE_ID__",
"external_subscription_id": "__YOUR_SUBSCRIPTION_ID__",
"code": "__BILLABLE_METRIC_CODE__",
"timestamp": $(date +%s),
"properties": {
"custom_field": 12
}
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import Event
client = Client(api_key='__YOUR_API_KEY__')
event = Event(
transaction_id="__UNIQUE_ID__",
external_subscription_id="__UNIQUE_ID__",
code="__BILLABLE_METRIC_CODE__",
timestamp=1650893379,
properties={"custom_field": "custom"}
)
try:
client.events.create(event)
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.events.create(
transaction_id: "__UNIQUE_ID__",
external_subscription_id: "__SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: Time.now.to_i,
properties: {
custom_field: 12
}
)
await client.events.createEvent({
event: {
transaction_id: "__UNIQUE_TRANSACTION_ID__",
external_subscription_id: "__UNIQUE_SUBSCRIPTION_ID__",
code: "__BILLABLE_METRIC_CODE__",
timestamp: 1650893379,
properties: { customField: "custom" },
},
});
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
ctx := context.Background()
lagoClient := lago.New().SetApiKey("__YOUR_API_KEY__")
eventInput := &lago.EventInput{
TransactionID: "__UNIQUE_TRANSACTION_ID__",
ExternalSubscriptionID: "__UNIQUE_SUBSCRIPTION_ID__",
Code: "__BILLABLE_METRIC_CODE__",
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
Properties: map[string]interface{}{
"nbusers": "12",
},
}
res, err := lagoClient.Event().Create(ctx, eventInput)
if err != nil {
// err is *lago.Error
panic(err)
}
// res is *lago.Event
fmt.Println(*res)
}
Was this page helpful?
⌘I