Skip to main content

Overview

The UserBoost REST API allows you to track events from any language or framework that can make HTTP requests. Use these cURL examples as a reference for implementing in your preferred language.

Authentication

All API requests require authentication using your server-side API key:
Authorization: Bearer ub_live_your_api_key_here

Basic Event Tracking

Single Event (Primary Endpoint)

Track events using the /v1/event endpoint - the recommended approach for most applications:

Minimal Payload (Required Fields Only)

curl -X POST https://api.userboo.st/v1/event \
  -H "Authorization: Bearer ub_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "user_signed_up",
    "user": {
      "id": "user_123"
    }
  }'

πŸ“‹ Full Payload (With Optional Fields)

curl -X POST https://api.userboo.st/v1/event \
  -H "Authorization: Bearer ub_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "user_signed_up",
    "user": {
      "id": "user_123",
      "email": "john@example.com",
      "traits": {
        "plan": "free"
      }
    },
    "timestamp": "2025-01-15T10:00:00Z",
    "properties": {
      "source": "website"
    }
  }'

πŸ“‹ Field Requirements

FieldRequiredTypeDescription
βœ… eventREQUIREDstringEvent name (e.g., β€œuser_signed_up”)
βœ… userREQUIREDobjectUser object with required id field
❌ timestampOptionalstringISO 8601 timestamp (defaults to now)
❌ propertiesOptionalobjectEvent-specific data

🎨 User Object Format

The user field requires an object with an id field:
Important: User data must be provided as an object. String format like "user": "user_123" is no longer supported and will result in validation errors.
  • Minimal User Object
  • πŸ“‹ User Object with Traits (Rich Data)
curl -X POST https://api.userboo.st/v1/event \
  -H "Authorization: Bearer ub_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "button_clicked",
    "user": {
      "id": "user_123"
    },
    "properties": {
      "button": "signup_cta",
      "page": "homepage"
    }
  }'
βœ… Best for: Quick event tracking with existing user IDs

πŸ“‹ User Object Structure

FieldRequiredTypeDescription
βœ… idREQUIREDstringUnique user identifier
❌ emailOptionalstringUser email address
❌ traitsOptionalobjectUser attributes (plan, company, etc.)

πŸ“¦ Batch Events (Advanced Use Case)

For high-volume applications only - send multiple events using /v1/events:
curl -X POST https://api.userboo.st/v1/events \
  -H "Authorization: Bearer ub_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "sent_at": "2025-01-15T10:00:00Z",
    "events": [
      {
        "type": "event",
        "name": "user_registered",
        "user": {
          "id": "user_123",
          "email": "john@example.com"
        },
        "timestamp": "2025-01-15T10:00:00Z"
      },
      {
        "type": "event",
        "name": "profile_completed",
        "user": {
          "id": "user_123"
        },
        "timestamp": "2025-01-15T10:05:00Z",
        "properties": {
          "completion_rate": 100
        }
      }
    ]
  }'

πŸ“‹ Batch Fields Requirements

FieldRequiredTypeDescription
βœ… sent_atREQUIREDstringBatch timestamp (ISO 8601)
βœ… eventsREQUIREDarrayArray of event objects
βœ… events[].typeREQUIREDstringMust be β€œevent”
βœ… events[].nameREQUIREDstringEvent name
βœ… events[].userREQUIREDobjectUser object with required id field
❌ events[].timestampOptionalstringEvent timestamp
❌ events[].propertiesOptionalobjectEvent data
πŸ‘‰ Use /v1/event for most applications - batch endpoint is only needed for 100+ events per minute

User Identification

Update user profile information:
curl -X POST https://api.userboo.st/v1/events \
  -H "Authorization: Bearer ub_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "sent_at": "2025-01-15T10:00:00Z",
    "events": [{
      "type": "identify",
      "user": {
        "id": "user_123",
        "email": "john@example.com",
        "traits": {
          "name": "John Doe",
          "plan": "premium",
          "created_at": "2025-01-01T00:00:00Z"
        }
      },
      "timestamp": "2025-01-15T10:00:00Z"
    }]
  }'

Language Examples

Python (requests)

Simplified single event tracking:
import requests
import json
from datetime import datetime

def track_event(event_name, user, properties=None):
    payload = {
        "name": event_name,
        "user": user,
        "timestamp": datetime.utcnow().isoformat() + "Z",
        "properties": properties or {}
    }

    response = requests.post(
        "https://api.userboo.st/v1/event",
        headers={
            "Authorization": "Bearer ub_live_your_api_key_here",
            "Content-Type": "application/json"
        },
        json=payload
    )

    return response.json()

# Usage with simple user ID
track_event("user_signed_up", "user_123", {
    "email": "john@example.com",
    "plan": "free"
})

# Usage with user object and traits
track_event("purchase_completed", {
    "id": "user_123",
    "email": "john@example.com",
    "traits": {
        "plan": "premium",
        "company": "Acme Corp"
    }
}, {
    "amount": 99.00,
    "product": "pro_plan"
})

Go

Simplified single event tracking:
package main

import (
    "bytes"
    "encoding/json"
    "net/http"
    "time"
)

// User can be a string or an object
type User struct {
    ID     string                 `json:"id"`
    Email  string                 `json:"email,omitempty"`
    Traits map[string]interface{} `json:"traits,omitempty"`
}

type EventRequest struct {
    Name       string      `json:"name"`
    User       interface{} `json:"user"` // Can be string or User object
    Timestamp  string      `json:"timestamp"`
    Properties map[string]interface{} `json:"properties,omitempty"`
}

// Simple user ID version
func trackEvent(eventName, userID string, properties map[string]interface{}) error {
    payload := EventRequest{
        Name:       eventName,
        User:       userID, // Simple string
        Timestamp:  time.Now().UTC().Format(time.RFC3339),
        Properties: properties,
    }

    return sendEvent(payload)
}

// Rich user data version
func trackEventWithUser(eventName string, user User, properties map[string]interface{}) error {
    payload := EventRequest{
        Name:       eventName,
        User:       user, // User object with traits
        Timestamp:  time.Now().UTC().Format(time.RFC3339),
        Properties: properties,
    }

    return sendEvent(payload)
}

func sendEvent(payload EventRequest) error {
    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", "https://api.userboo.st/v1/event", bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer ub_live_your_api_key_here")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    return nil
}

// Usage examples
func main() {
    // Simple user ID
    trackEvent("user_signed_up", "user_123", map[string]interface{}{
        "email": "john@example.com",
        "plan":  "free",
    })

    // Rich user data with traits
    trackEventWithUser("purchase_completed", User{
        ID:    "user_123",
        Email: "john@example.com",
        Traits: map[string]interface{}{
            "plan":    "premium",
            "company": "Acme Corp",
        },
    }, map[string]interface{}{
        "amount":  99.00,
        "product": "pro_plan",
    })
}

PHP

Simplified single event tracking:
<?php

function trackEvent($eventName, $user, $properties = []) {
    $payload = [
        'name' => $eventName,
        'user' => $user,
        'timestamp' => date('c'),
        'properties' => $properties
    ];

    $options = [
        'http' => [
            'header' => [
                'Authorization: Bearer ub_live_your_api_key_here',
                'Content-Type: application/json'
            ],
            'method' => 'POST',
            'content' => json_encode($payload)
        ]
    ];

    $context = stream_context_create($options);
    $result = file_get_contents('https://api.userboo.st/v1/event', false, $context);

    return json_decode($result, true);
}

// Usage with simple user ID
trackEvent('user_signed_up', 'user_123', [
    'email' => 'john@example.com',
    'plan' => 'free'
]);

// Usage with user object and traits
trackEvent('purchase_completed', [
    'id' => 'user_123',
    'email' => 'john@example.com',
    'traits' => [
        'plan' => 'premium',
        'company' => 'Acme Corp'
    ]
], [
    'amount' => 99.00,
    'product' => 'pro_plan'
]);
?>

πŸ“ˆ Payload Reference

Single Event Payload (/v1/event - Primary)

Minimal required payload:
{
  "name": "event_name",
  "user": "user_123"
}
  • Minimal Payload
  • πŸ“‹ Standard Payload
  • πŸ“‹ Full Payload
{
  "name": "button_clicked",
  "user": "user_123"
}
βœ… Required fields only - timestamp auto-generated

πŸ“¦ Batch Events Payload (/v1/events - Advanced)

For high-volume applications only:
{
  "sent_at": "2025-01-15T10:00:00Z",
  "events": [
    {
      "type": "event",
      "name": "event_name",
      "user": "user_123",
      "properties": {
        "custom_property": "value"
      }
    }
  ]
}

🎨 Properties vs Traits

  • πŸ“Š Properties (Event Data)
  • πŸ‘€ Traits (User Attributes)
{
  "name": "purchase_completed",
  "user": "user_123",
  "properties": {
    "amount": 99.00,
    "product": "pro_plan",
    "payment_method": "stripe",
    "discount_code": "SAVE20"
  }
}
πŸ‘‰ Use for: Event context, transaction details, session info, action metadata
Quick Rule: - Properties = What happened in this event πŸ“Š - Traits = Who the user is πŸ‘€

Response Format

Success Response

{
  "success": true,
  "events_processed": 1
}

Error Response

{
  "error": "Invalid API key",
  "code": 401
}

🎯 Best Practices

  1. Use /v1/event endpoint for most applications (simpler, faster)
  2. πŸ“Š Send minimal required fields - name and user are often enough
  3. πŸ“‹ Use meaningful event names that describe user actions
  4. πŸ‘€ Include user traits when you have rich user data
  5. πŸ”’ Use environment variables for API keys
  6. ⚑ Only batch events if you have 100+ events per minute

🚦 Rate Limits

Limit Type/v1/event/v1/events (batch)
Events/sec10001000 total events
Payload size1 MB10 MB
Events per request1Up to 100
πŸ‘‰ Best forMost appsHigh-volume only

Support

For REST API questions, contact support@userboo.st
⌘I