Skip to main content

Meter Events

1 operation under /v1/meter-events (POST): parameters, status codes, refusal bodies, and the same request in curl, HTTP, Python and TypeScript.

2 min read
View MarkdownEdit on GitHub

Base URL: https://api.codespar.dev

Every operation below requires a Bearer token. See Authentication.

POST /v1/meter-events

POSThttps://api.codespar.dev/v1/meter-events

Record a usage event

event names the meter (its event_name) in the caller's project; the meter must exist. customer is the tenant's customer id. value is required for sum, max and last meters (non-negative, up to six decimals) and must be omitted (or 1) for a count meter. timestamp is the event's own time, default now; it must fall in the previous or the current cycle and at most 5 minutes ahead.

IDEMPOTENT ON event_id: an id already recorded with the same meter, customer and value (and the same timestamp, when one is given) answers 200 with duplicate: true and is counted once. A different payload under a known id is refused with 409.

Request body

FieldTypeRequiredDescription
customerstringyes—
eventstringyes—
event_idstringyes—
timestampstring (date-time)no—
valuenumber | stringno—

Responses

StatusBodyDescription
200objectOK
201objectOK
400objectBad Request.
404objectNo meter in this project for that event name.
409objectThe event_id was recorded with a different payload.

Response 200

FieldTypeRequiredDescription
customerstringyes—
customer_namestring,nullyesThe consumer's display name when customer is a consumer id of the organization.
duplicatetrueyes—
eventstringyes—
event_idstringyes—
meter_idstringyes—
object"meter_event"yes—
occurred_atstringyesThe event's own time; decides its cycle.
received_atstringyes—
valuestringyes1 for a count meter; the event's value otherwise.
Example request
curl -X POST https://api.codespar.dev/v1/meter-events \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "event": "string",
       "customer": "string",
       "value": 1000,
       "event_id": "event_0000000000000000",
       "timestamp": "2026-01-15T12:00:00.000Z"
     }'
POST /v1/meter-events HTTP/1.1
Host: api.codespar.dev
Authorization: Bearer $CODESPAR_API_KEY
Content-Type: application/json

{
  "event": "string",
  "customer": "string",
  "value": 1000,
  "event_id": "event_0000000000000000",
  "timestamp": "2026-01-15T12:00:00.000Z"
}
import os
import requests

res = requests.post(
    "https://api.codespar.dev/v1/meter-events",
    headers={"Authorization": f"Bearer {os.environ['CODESPAR_API_KEY']}"},
    json={
      "event": "string",
      "customer": "string",
      "value": 1000,
      "event_id": "event_0000000000000000",
      "timestamp": "2026-01-15T12:00:00.000Z"
    },
)
res.raise_for_status()
data = res.json()
const res = await fetch("https://api.codespar.dev/v1/meter-events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CODESPAR_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "event": "string",
    "customer": "string",
    "value": 1000,
    "event_id": "event_0000000000000000",
    "timestamp": "2026-01-15T12:00:00.000Z"
  }),
});

const data = await res.json();
const result = await cs.api.post("/v1/meter-events", {
  body: {
    event: "string",
    customer: "string",
    value: 1000,
    event_id: "event_0000000000000000",
    timestamp: "2026-01-15T12:00:00.000Z"
  }
});
Example response 200
application/json
{
  "object": "meter_event",
  "event_id": "event_0000000000000000",
  "meter_id": "meter_0000000000000000",
  "customer": "string",
  "customer_name": "Example",
  "value": "string",
  "occurred_at": "string",
  "received_at": "string",
  "event": "string",
  "duplicate": true
}
Meter Events | CodeSpar