Skip to main content

Overview

Events track customer usage for metered billing. Send events to Polar as they occur, and they’ll be aggregated by meters and billed accordingly.

The Event Object

id
string
required
Unique identifier
name
string
required
Event name
customer_id
string
required
Customer ID
timestamp
string
required
When the event occurred (ISO 8601)
properties
object
required
Event properties (key-value pairs)
source
enum
required
Source: api or import
organization_id
string
required
Organization ID
created_at
string
required
When event was ingested

Ingest Events

cURL
curl -X POST "https://api.polar.sh/v1/events/ingest" \
  -H "Authorization: Bearer polar_pat_..." \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "name": "api_request",
        "customer_id": "cust_123",
        "timestamp": "2024-01-15T10:30:00Z",
        "properties": {
          "endpoint": "/api/v1/users",
          "response_time_ms": 150
        }
      }
    ]
  }'
Events are processed asynchronously. They’ll be available for querying within a few seconds.

Request Body

events
array
required
Array of events to ingest (max 100 per request)

Response

ingested
integer
Number of events successfully ingested
errors
array
Array of errors for failed events

List Events

cURL
curl -X GET "https://api.polar.sh/v1/events" \
  -H "Authorization: Bearer polar_pat_..."

Query Parameters

organization_id
string
Filter by organization
customer_id
string
Filter by customer
external_customer_id
string
Filter by external customer ID
meter_id
string
Filter events matching a meter’s filter
name
string
Filter by event name
filter
string
JSON filter clause (same format as meter filters)
start_timestamp
string
Filter events after this timestamp
end_timestamp
string
Filter events before this timestamp
metadata
object
Filter by metadata

Get Event

cURL
curl -X GET "https://api.polar.sh/v1/events/{id}" \
  -H "Authorization: Bearer polar_pat_..."

Path Parameters

id
string
required
Event ID

Get Event Statistics

cURL
curl -X GET "https://api.polar.sh/v1/events/statistics" \
  -H "Authorization: Bearer polar_pat_..." \
  -H "Content-Type: application/json"
Get aggregated statistics for events over time.

Query Parameters

organization_id
string
required
Organization ID
start_timestamp
string
required
Start of time range
end_timestamp
string
required
End of time range
interval
enum
required
Time interval: hour, day, week, or month
meter_id
string
Aggregate events for specific meter
aggregation
enum
Aggregation function: count, sum, avg, min, or max
aggregate_field
string
Property to aggregate (for sum/avg/min/max)

Response

Returns time series data:
[
  {
    "timestamp": "2024-01-15T00:00:00Z",
    "value": 1234
  },
  {
    "timestamp": "2024-01-16T00:00:00Z",
    "value": 2345
  }
]

Examples

Ingest Single Event

curl -X POST "https://api.polar.sh/v1/events/ingest" \
  -H "Authorization: Bearer polar_pat_..." \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "name": "api_request",
        "external_customer_id": "user_123",
        "timestamp": "2024-01-15T10:30:00Z",
        "properties": {
          "method": "POST",
          "endpoint": "/api/v1/data",
          "bytes_sent": 2048
        },
        "idempotency_key": "req_abc123"
      }
    ]
  }'

Ingest Batch of Events

curl -X POST "https://api.polar.sh/v1/events/ingest" \
  -H "Authorization: Bearer polar_pat_..." \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "name": "api_request",
        "customer_id": "cust_123",
        "timestamp": "2024-01-15T10:30:00Z",
        "properties": {"endpoint": "/api/users", "count": 1}
      },
      {
        "name": "api_request",
        "customer_id": "cust_123",
        "timestamp": "2024-01-15T10:31:00Z",
        "properties": {"endpoint": "/api/posts", "count": 1}
      },
      {
        "name": "data_processed",
        "customer_id": "cust_123",
        "timestamp": "2024-01-15T10:32:00Z",
        "properties": {"bytes": 10485760, "rows": 5000}
      }
    ]
  }'

Query Events for Customer

curl -X GET "https://api.polar.sh/v1/events?customer_id=cust_123&start_timestamp=2024-01-01T00:00:00Z&end_timestamp=2024-01-31T23:59:59Z" \
  -H "Authorization: Bearer polar_pat_..."

Get Daily Statistics

curl -X GET "https://api.polar.sh/v1/events/statistics?organization_id=org_123&start_timestamp=2024-01-01T00:00:00Z&end_timestamp=2024-01-31T23:59:59Z&interval=day&aggregation=count" \
  -H "Authorization: Bearer polar_pat_..."

Build docs developers (and LLMs) love