Docs

Audit Log API

The Audit Log API provides access to the complete timeline of automation activities, with powerful filtering and search capabilities for compliance, monitoring, and debugging purposes.

Base URL

/wp-json/odcm/v1/audit/

Authentication: Requires manage_woocommerce capability and proper WordPress authentication.

Endpoints

GET /audit/

List audit log entries with filtering and pagination.

Parameters:

  • status (string, optional) – Filter by entry status: success, error, warning, info
  • event_type (string, optional) – Filter by event type: rule_evaluation, webhook, manual, security
  • source (string, optional) – Filter by source: automation, manual, webhook, gateway
  • order_id (int, optional) – Filter by specific order ID
  • date_start (string, optional) – Start date (ISO 8601 format)
  • date_end (string, optional) – End date (ISO 8601 format)
  • search (string, optional) – Search in summary and details
  • per_page (int, optional) – Items per page (default: 20, max: 100)
  • page (int, optional) – Page number (default: 1)

Example Request:

curl "https://yoursite.com/wp-json/odcm/v1/audit/?status=success&event_type=rule_evaluation&per_page=10" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response:

{
  "success": true,
  "data": {
    "items": [
      {
        "id": 456,
        "timestamp": "2025-01-15T14:30:25Z",
        "status": "success",
        "event_type": "rule_evaluation",
        "source": "automation",
        "summary": "Rule 'Auto-Complete Virtual Orders' executed successfully",
        "order_id": 789,
        "rule_id": 123,
        "process_id": "proc_abc123",
        "components": [
          {
            "type": "trigger",
            "name": "Order Processing",
            "status": "fired",
            "details": "Order status changed to Processing"
          },
          {
            "type": "condition", 
            "name": "Product Type",
            "status": "passed",
            "details": "All products are virtual"
          },
          {
            "type": "action",
            "name": "Complete Order",
            "status": "executed",
            "details": "Order status changed to Completed"
          }
        ],
        "context": {
          "order": {
            "id": 789,
            "total": "29.99",
            "status": "completed",
            "items_count": 1
          },
          "rule": {
            "id": 123,
            "name": "Auto-Complete Virtual Orders"
          }
        }
      }
    ],
    "total": 1250,
    "page": 1,
    "per_page": 10,
    "total_pages": 125
  }
}

GET /audit/{id}

Get a specific audit log entry with full details.

Parameters:

  • id (int, required) – Audit entry ID

Example Request:

curl "https://yoursite.com/wp-json/odcm/v1/audit/456" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response:

{
  "success": true,
  "data": {
    "id": 456,
    "timestamp": "2025-01-15T14:30:25Z",
    "status": "success",
    "event_type": "rule_evaluation",
    "source": "automation",
    "summary": "Rule 'Auto-Complete Virtual Orders' executed successfully",
    "order_id": 789,
    "rule_id": 123,
    "process_id": "proc_abc123",
    "components": [
      {
        "type": "trigger",
        "component_id": "order_processing",
        "name": "Order Processing",
        "status": "fired",
        "details": "Order status changed to Processing",
        "execution_time_ms": 15
      },
      {
        "type": "condition",
        "component_id": "product_type", 
        "name": "Product Type",
        "status": "passed",
        "details": "All products are virtual",
        "execution_time_ms": 8
      },
      {
        "type": "action",
        "component_id": "complete_order",
        "name": "Complete Order",
        "status": "executed",
        "details": "Order status changed to Completed",
        "execution_time_ms": 42
      }
    ],
    "context": {
      "order": {
        "id": 789,
        "total": "29.99",
        "status": "completed",
        "currency": "USD",
        "items_count": 1,
        "customer_id": 45
      },
      "rule": {
        "id": 123,
        "name": "Auto-Complete Virtual Orders",
        "trigger_type": "order_processing"
      },
      "performance": {
        "total_execution_time_ms": 65,
        "memory_usage_kb": 1024
      }
    },
    "raw_data": {
      "trigger_payload": {
        "order_id": 789,
        "old_status": "pending",
        "new_status": "processing"
      }
    }
  }
}

GET /audit/timeline/{order_id}

Get the complete audit timeline for a specific order.

Parameters:

  • order_id (int, required) – WooCommerce order ID

Example Request:

curl "https://yoursite.com/wp-json/odcm/v1/audit/timeline/789" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response:

{
  "success": true,
  "data": {
    "order_id": 789,
    "timeline": [
      {
        "id": 455,
        "timestamp": "2025-01-15T14:30:20Z",
        "event_type": "webhook",
        "summary": "Payment confirmation received from Stripe",
        "status": "success"
      },
      {
        "id": 456,
        "timestamp": "2025-01-15T14:30:25Z", 
        "event_type": "rule_evaluation",
        "summary": "Rule 'Auto-Complete Virtual Orders' executed successfully",
        "status": "success"
      }
    ],
    "total_entries": 2
  }
}

GET /audit/stats

Get aggregate statistics about automation activity.

Parameters:

  • period (string, optional) – Time period: today, week, month, year (default: week)
  • group_by (string, optional) – Group results by: status, event_type, source, rule

Example Request:

curl "https://yoursite.com/wp-json/odcm/v1/audit/stats?period=week&group_by=status" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response:

{
  "success": true,
  "data": {
    "period": "week",
    "period_start": "2025-01-08T00:00:00Z",
    "period_end": "2025-01-15T23:59:59Z",
    "totals": {
      "total_entries": 1250,
      "success": 1180,
      "error": 25,
      "warning": 30,
      "info": 15
    },
    "groups": [
      {
        "group": "success",
        "count": 1180,
        "percentage": 94.4
      },
      {
        "group": "error", 
        "count": 25,
        "percentage": 2.0
      },
      {
        "group": "warning",
        "count": 30,
        "percentage": 2.4
      },
      {
        "group": "info",
        "count": 15,
        "percentage": 1.2
      }
    ],
    "trends": {
      "daily_counts": [
        {"date": "2025-01-15", "count": 185},
        {"date": "2025-01-14", "count": 210},
        {"date": "2025-01-13", "count": 145}
      ]
    }
  }
}

Bulk Operations

POST /audit/export

Export audit log entries in various formats.

Request Body:

{
  "format": "csv",
  "filters": {
    "status": "success",
    "date_start": "2025-01-01T00:00:00Z",
    "date_end": "2025-01-31T23:59:59Z"
  },
  "fields": ["timestamp", "summary", "order_id", "status"]
}

Example Response:

{
  "success": true,
  "data": {
    "export_id": "exp_xyz789",
    "download_url": "https://yoursite.com/wp-content/uploads/order-daemon/exports/audit_exp_xyz789.csv",
    "expires_at": "2025-01-16T14:30:25Z",
    "record_count": 450
  }
}

DELETE /audit/cleanup

Delete old audit entries based on retention policies.

Request Body:

{
  "older_than_days": 30,
  "status_filter": ["error", "warning"],
  "dry_run": true
}

Example Response:

{
  "success": true,
  "data": {
    "entries_to_delete": 15,
    "size_freed_kb": 245,
    "dry_run": true,
    "message": "15 entries would be deleted (245 KB freed)"
  }
}

Advanced Filtering (Pro Features)

GET /audit/advanced-search

Advanced search with complex filtering logic.

Note: This endpoint requires Order Daemon Pro.

Request Body:

{
  "filters": [
    {
      "field": "status",
      "operator": "in", 
      "value": ["success", "warning"]
    },
    {
      "field": "execution_time_ms",
      "operator": ">",
      "value": 100
    }
  ],
  "logic": "AND",
  "order_by": "timestamp",
  "order": "DESC",
  "per_page": 25
}

GET /audit/correlate

Find related audit entries across different orders or time periods.

Note: This endpoint requires Order Daemon Pro.

Real-time Updates

WebSocket Connection

For real-time audit log updates, Order Daemon Pro provides a WebSocket endpoint.

Connection: wss://yoursite.com/wp-json/odcm/v1/audit/stream

Example Message:

{
  "type": "new_entry",
  "data": {
    "id": 457,
    "timestamp": "2025-01-15T14:35:00Z",
    "event_type": "rule_evaluation",
    "summary": "Rule executed",
    "status": "success"
  }
}

Error Responses

Validation Error (400):

{
  "success": false,
  "message": "Invalid date format",
  "code": "validation_error"
}

Premium Feature Error (403):

{
  "success": false,
  "message": "Advanced filtering requires Order Daemon Pro",
  "code": "odcm_premium_blocked"
}

Entry Not Found (404):

{
  "success": false,
  "message": "Audit entry not found",
  "code": "entry_not_found"
}

Integration Examples

JavaScript – Monitor Recent Activity:

// Poll for recent entries
setInterval(() => {
  wp.apiFetch({
    path: '/odcm/v1/audit/?per_page=5&status=error'
  }).then(response => {
    const errors = response.data.items;
    if (errors.length > 0) {
      console.warn('Recent automation errors:', errors);
    }
  });
}, 30000); // Check every 30 seconds

PHP – Export Weekly Reports:

// Generate weekly compliance report
$request = new WP_REST_Request('POST', '/odcm/v1/audit/export');
$request->set_body_params([
    'format' => 'csv',
    'filters' => [
        'date_start' => date('c', strtotime('-7 days')),
        'date_end' => date('c')
    ]
]);

$response = rest_do_request($request);
if ($response->is_success()) {
    $export_data = $response->get_data()['data'];
    // Process export...
}

Performance Considerations

  • Large datasets: Use pagination and filtering to limit response sizes
  • Date ranges: Narrow date ranges for better performance on large logs
  • Real-time: Consider WebSocket connections for real-time monitoring instead of polling
  • Exports: Large exports are processed asynchronously

Data Retention

  • Core: 30-day retention by default
  • Pro: Configurable retention policies
  • Privacy: Personal data is minimized in audit entries
  • Cleanup: Automated cleanup based on configured policies

Was this article helpful?

  • Loading...
Table of Contents
  • Loading...