API Reference

The Clayva API is organized around REST. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

Base URL: https://api.clayva.com/v1
Current Version: v1.0.0
SDKs Available: JavaScript, Python, Ruby, Go, PHP

Authentication

The Clayva API uses API keys to authenticate requests. You can view and manage your API keys in the Clayva Dashboard. Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Authentication to the API is performed via HTTP Bearer Auth. Provide your API key as the bearer token:

Authorization: Bearer YOUR_API_KEY

All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Events API

Events are the core of Clayva's analytics. Use these endpoints to track user actions, system events, and any custom events in your application.

Track Event

POST /events/track
Auth Required 1000/min

Track a single event

Records a single event with associated properties and user information.

Request Parameters

Feature
Parameter
Type
Required
Description
event
event string The name of the event to track
properties
Any JSON-serializable data
properties object Custom properties for the event
timestamp
Defaults to current time if not provided
timestamp string ISO 8601 timestamp
userId
userId string The ID of the user performing the event
anonymousId
anonymousId string Anonymous identifier for the user
context
context object Additional context about the event

Example Request

curl -X POST https://api.clayva.com/v1/events/track \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "Product Viewed",
    "userId": "user_123",
    "properties": {
      "productId": "SKU-456",
      "productName": "Wireless Mouse",
      "price": 29.99
    }
  }'
const response = await fetch('https://api.clayva.com/v1/events/track', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    event: 'Product Viewed',
    userId: 'user_123',
    properties: {
      productId: 'SKU-456',
      productName: 'Wireless Mouse',
      price: 29.99
    }
  })
});

const data = await response.json();
import requests

response = requests.post(
    'https://api.clayva.com/v1/events/track',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'event': 'Product Viewed',
        'userId': 'user_123',
        'properties': {
            'productId': 'SKU-456',
            'productName': 'Wireless Mouse',
            'price': 29.99
        }
    }
)

data = response.json()

Success Response

200 OK

{
  "success": true,
  "data": {
    "eventId": "evt_2KtY3kPl9vR8mNxZ",
    "event": "Product Viewed",
    "userId": "user_123",
    "timestamp": "2024-01-15T10:30:00Z",
    "properties": {
      "productId": "SKU-456",
      "productName": "Wireless Mouse",
      "price": 29.99
    },
    "context": {
      "library": {
        "name": "clayva-js",
        "version": "1.2.0"
      }
    }
  }
}

Error Response

400 Bad Request

{
  "success": false,
  "error": {
    "code": "INVALID_EVENT_NAME",
    "message": "Event name cannot be empty or null",
    "details": {
      "field": "event",
      "provided": null
    }
  }
}

Batch Events

POST /events/batch
Auth Required 100/min

Track multiple events

Records multiple events in a single request for improved performance.

The batch endpoint accepts an array of events, each following the same structure as the single event endpoint. Maximum 1000 events per batch.

{
  "events": [
    {
      "event": "Product Viewed",
      "userId": "user_123",
      "properties": { ... }
    },
    {
      "event": "Add to Cart",
      "userId": "user_123",
      "properties": { ... }
    }
  ]
}

Get Event

GET /events:eventId
Auth Required 1000/min

Retrieve event details

Get detailed information about a specific event by its ID.

Users API

Manage user profiles and properties. These endpoints allow you to identify users, update their attributes, and retrieve user information.

Identify User

POST /users/identify
Auth Required 500/min

Identify a user

Create or update a user profile with traits and attributes.

Get User

GET /users:userId
Auth Required 1000/min

Get user profile

Retrieve complete user profile including all traits and computed properties.

Update User

PATCH /users:userId
Auth Required 500/min

Update user traits

Partially update user traits without replacing the entire profile.

Workspaces API

Manage workspaces and their settings. Workspaces allow you to organize your analytics data and control access for your team.

GET /workspaces
Auth Required 100/min

List workspaces

Get all workspaces accessible to the authenticated user.

POST /workspaces
Auth Required 10/min

Create workspace

Create a new workspace for organizing your analytics data.

Rate Limits

The Clayva API implements rate limiting to ensure fair usage and maintain service reliability. Rate limits are enforced per API key.

Rate Limit Headers: Every API response includes headers showing your current rate limit status:
  • X-RateLimit-Limit - Maximum requests per window
  • X-RateLimit-Remaining - Requests remaining in current window
  • X-RateLimit-Reset - Unix timestamp when the window resets

Default Rate Limits

Feature
Endpoint Category
Free Tier
Pro Tier
Enterprise
Event Tracking
100/min 1000/min Custom
Batch Events
10/min 100/min Custom
User Operations
50/min 500/min Custom
Query APIs
20/min 200/min Custom
Admin APIs
5/min 50/min Custom

Error Handling

Clayva uses conventional HTTP response codes to indicate the success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that failed given the information provided, and codes in the 5xx range indicate an error with Clayva's servers.

Error Codes

Feature
Error Code
HTTP Status
Description
UNAUTHORIZED
UNAUTHORIZED 401 Invalid or missing API key
FORBIDDEN
FORBIDDEN 403 Access denied to this resource
NOT_FOUND
NOT_FOUND 404 Resource not found
INVALID_REQUEST
INVALID_REQUEST 400 Request validation failed
RATE_LIMITED
RATE_LIMITED 429 Too many requests
SERVER_ERROR
SERVER_ERROR 500 Internal server error
Need Help? Check out our SDK documentation for language-specific examples, or contact our support team for assistance.