Skip to main content
POST
/
events
/
batch
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"

curl --location --request POST "$LAGO_URL/api/v1/events/batch" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
	"events": [
      {
        "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 BatchEvent

client = Client(api_key='__YOUR_API_KEY__')

# Create a list of events
batch_event = BatchEvent(events=[
    Event(
        transaction_id="__UNIQUE_ID_1__",
        external_subscription_id="__SUBSCRIPTION_ID_1__",
        code="__BILLABLE_METRIC_CODE__",
        timestamp=1650893379,
        properties={"custom_field": "custom"}
    ),
    Event(
        transaction_id="__UNIQUE_ID_2__",
        external_subscription_id="__SUBSCRIPTION_ID_2__",
        code="__BILLABLE_METRIC_CODE__",
        timestamp=1650893380,
        properties={"custom_field": "custom"}
    )
    # Add more events as needed
])
try:
    client.events.batch_create(batch_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__')

# Create an array of event hashes
events = [
  {
    transaction_id: "__UNIQUE_ID_1__",
    external_subscription_id: "__SUBSCRIPTION_ID_1__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: Time.now.to_i,
    properties: {
      custom_field: "custom value 1"
    }
  },
  {
    transaction_id: "__UNIQUE_ID_2__",
    external_subscription_id: "__SUBSCRIPTION_ID_2__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: Time.now.to_i,
    properties: {
      custom_field: "custom value 2"
    }
  }
  # Add more events as needed
]

client.events.batch_create(events)
const batchEvent = [
  {
    transaction_id: "__UNIQUE_TRANSACTION_ID_1__",
    external_subscription_id: "__SUBSCRIPTION_ID_1__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: 1650893379,
    properties: { customField: "custom1" },
  },
  {
    transaction_id: "__UNIQUE_TRANSACTION_ID_2__",
    external_subscription_id: "__SUBSCRIPTION_ID_2__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: 1650893380,
    properties: { customField: "custom2" },
  },
  // Add more events as needed
];

await client.events.createBatchEvents({ events: batchEvent });

import "fmt"
import "github.com/getlago/lago-go-client"

func main() {
  ctx := context.Background()
  lagoClient := lago.New().SetApiKey("__YOUR_API_KEY__")

  event := 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",
    },
  }

  batchInput := make([]lago.EventInput, 1)
  batchInput[0] = event

  res, err := lagoClient.Event().Batch(ctx, &batchInput)
}
{
  "status": 422,
  "error": "Unprocessable Entity",
  "code": "validation_errors",
  "error_details": {
    "1": {
      "transaction_id": [
        "value_already_exist"
      ]
    }
  }
}
Batches are atomic. If a single event is invalid, Lago rejects the entire batch with a 422 and persists nothing, including the valid events in the same request. “Invalid” covers a bad schema, an unknown subscription, or a duplicate transaction_id (value_already_exist). The error_details object reports failures by the event’s index in the array you sent, not by transaction_id, so keep your array order to trace an index back to its source event.
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"

curl --location --request POST "$LAGO_URL/api/v1/events/batch" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
	"events": [
      {
        "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 BatchEvent

client = Client(api_key='__YOUR_API_KEY__')

# Create a list of events
batch_event = BatchEvent(events=[
    Event(
        transaction_id="__UNIQUE_ID_1__",
        external_subscription_id="__SUBSCRIPTION_ID_1__",
        code="__BILLABLE_METRIC_CODE__",
        timestamp=1650893379,
        properties={"custom_field": "custom"}
    ),
    Event(
        transaction_id="__UNIQUE_ID_2__",
        external_subscription_id="__SUBSCRIPTION_ID_2__",
        code="__BILLABLE_METRIC_CODE__",
        timestamp=1650893380,
        properties={"custom_field": "custom"}
    )
    # Add more events as needed
])
try:
    client.events.batch_create(batch_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__')

# Create an array of event hashes
events = [
  {
    transaction_id: "__UNIQUE_ID_1__",
    external_subscription_id: "__SUBSCRIPTION_ID_1__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: Time.now.to_i,
    properties: {
      custom_field: "custom value 1"
    }
  },
  {
    transaction_id: "__UNIQUE_ID_2__",
    external_subscription_id: "__SUBSCRIPTION_ID_2__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: Time.now.to_i,
    properties: {
      custom_field: "custom value 2"
    }
  }
  # Add more events as needed
]

client.events.batch_create(events)
const batchEvent = [
  {
    transaction_id: "__UNIQUE_TRANSACTION_ID_1__",
    external_subscription_id: "__SUBSCRIPTION_ID_1__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: 1650893379,
    properties: { customField: "custom1" },
  },
  {
    transaction_id: "__UNIQUE_TRANSACTION_ID_2__",
    external_subscription_id: "__SUBSCRIPTION_ID_2__",
    code: "__BILLABLE_METRIC_CODE__",
    timestamp: 1650893380,
    properties: { customField: "custom2" },
  },
  // Add more events as needed
];

await client.events.createBatchEvents({ events: batchEvent });

import "fmt"
import "github.com/getlago/lago-go-client"

func main() {
  ctx := context.Background()
  lagoClient := lago.New().SetApiKey("__YOUR_API_KEY__")

  event := 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",
    },
  }

  batchInput := make([]lago.EventInput, 1)
  batchInput[0] = event

  res, err := lagoClient.Event().Batch(ctx, &batchInput)
}
{
  "status": 422,
  "error": "Unprocessable Entity",
  "code": "validation_errors",
  "error_details": {
    "1": {
      "transaction_id": [
        "value_already_exist"
      ]
    }
  }
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Batch events payload

events
object[]
required

Response

Event received

events
object[]
required