OpsTrailsDocs
Console

API Reference

The OpsTrails HTTP API lets you record and query events programmatically. All endpoints use https://api.opstrails.dev as the base URL.

Authentication

All API requests require a Bearer token in the Authorization header. API keys are created in the console and come in two scopes:

📝 Note

API keys are prefixed with ot_ and stored as SHA-256 hashes. The full key is only shown once at creation time.

POST /api/v1/events

Record a new event on the timeline. Requires a READ_WRITE scoped API key.

Request Body

FieldTypeRequiredDescription
specversionstringrequiredMust be "1.0".
typestringrequiredEvent type, e.g. "deployment", "rollback". Max 100 chars.
sourcestringrequiredEvent origin URI, e.g. "//github.com/org/repo". Max 500 chars.
timestringrequiredTimestamp with timezone, or "NOW" for server time.
idstringoptionalCustom event ID. Auto-generated if omitted. Max 200 chars.
subjectstringoptionalFree-form context label, e.g. "production". Max 50 chars.
severitystringoptionalOne of LOW, MINOR, MAJOR, CRITICAL.
versionstringoptionalRelease version, e.g. "1.2.3". Max 50 chars.
datacontenttypestringoptionalMIME type of data field. Defaults to "application/json". Max 200 chars.
dataschemastringoptionalURI pointing to the schema for data. Max 500 chars.
dataobjectoptionalArbitrary JSON. Supports "description" (max 1000 chars) and "timezone" (max 50 chars) plus any extra fields.

Time Format Rules

Minimal Example

bash
curl -X POST https://api.opstrails.dev/api/v1/events \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "specversion": "1.0",
    "type": "deployment",
    "source": "//github.com/myorg/myrepo",
    "time": "NOW"
  }'

Full Example

bash
curl -X POST https://api.opstrails.dev/api/v1/events \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "specversion": "1.0",
    "type": "deployment",
    "source": "//github.com/myorg/myrepo",
    "time": "2025-01-15T14:30:00Z",
    "subject": "production",
    "severity": "LOW",
    "version": "1.2.3",
    "datacontenttype": "application/json",
    "data": {
      "description": "Deployed to production",
      "timezone": "Europe/London"
    }
  }'

GET /api/v1/events

Query events from the timeline. Requires a READ_ONLY or READ_WRITE scoped API key.

Query Parameters

FieldTypeRequiredDescription
typestringoptionalFilter by event type, e.g. "deployment".
sourcestringoptionalFilter by event source, e.g. "//github.com/org/repo".
subjectstringoptionalFilter by subject, e.g. "production".
severitystringoptionalFilter by severity: LOW, MINOR, MAJOR, or CRITICAL.
fromstringoptionalStart of time range. ISO 8601 datetime.
tostringoptionalEnd of time range. ISO 8601 datetime.
searchstringoptionalFree-text search across type, version, and source.
limitnumberoptionalMax events to return (1-100, default 25).

Example

bash
curl "https://api.opstrails.dev/api/v1/events?type=deployment&subject=production&source=//github.com/myorg/myrepo" \
  -H "Authorization: Bearer YOUR_API_KEY"

POST /api/v1/metrics/webhook

Receives metrics data from connected analytics providers. Used internally by the analytics integration system. See Connecting Providers for setup instructions.


Error Responses

All errors return a JSON body with the following structure:

json
{
  "success": false,
  "error": "time: Timezone is required. Use ISO 8601 with offset (e.g. +02:00 or Z) or \"NOW\"",
  "code": "VALIDATION_ERROR"
}

Error Codes

StatusCodeDescription
401UNAUTHORIZEDMissing or invalid Authorization header, or API key not found
403FORBIDDENAPI key has READ_ONLY scope — use a READ_WRITE key to push events
400VALIDATION_ERRORMissing or invalid fields, or time without timezone offset