DOCS

v1.3.28
 // Pro v1.2.20

 · Latest

Docs/API Reference/Rules Management API

Rules Management API

Complete CRUD for automation rules, plus component discovery endpoints for building rule management interfaces.

Base URL: /wp-json/odcm/v1/rule-builder

Authentication: Requires manage_woocommerce capability and WordPress authentication.

Typical workflow

Rules are built from components – you must discover what’s available before you can save a rule.

  1. GET /rule-builder/components – fetch all available triggers, conditions, and actions. Use the id fields from this response to build your rule body.
  2. GET /rule-builder/search-content – for conditions that reference products, categories, etc., use this to populate pickers.
  3. GET /rule/{id} – read the existing rule data when editing (rule IDs are WP post IDs from the odcm_order_rule CPT).
  4. PUT /rule/{id} – save the rule. The body wraps the rule data in a rule key alongside an optional audit key for audit trail context.

Rule data structure

Every rule has this shape – all keys are required in the body:

{
  "trigger": { "id": "order_processing", "settings": {} },
  "conditions": [],
  "primaryAction": { "id": "change_status_to_completed", "settings": {} },
  "secondaryActions": []
}
  • trigger – a single object {id, settings}. The trigger determines when the rule runs.
  • conditions – array of {id, settings} objects. All conditions must pass for actions to execute. Can be empty.
  • primaryAction – a single {id, settings} object. The main action that runs when the rule matches. Can be null.
  • secondaryActions – array of {id, settings} objects. Additional actions that run after the primary. Can be empty.

settings in each component corresponds to the JSON schema returned by get_settings_schema() on that component. Use the schema field from the components response to know what settings are valid.

Endpoints

GET /rule-builder/components

Get available triggers, conditions, and actions for building rules.

Parameters:

  • rule_id (int, optional) – current rule ID for state detection
curl "https://yoursite.com/wp-json/odcm/v1/rule-builder/components" 
  -u "your-username:xxxx xxxx xxxx xxxx xxxx xxxx"

Response:

{
  "triggers": [
    {
      "id": "order_processing",
      "label": "Order Processing",
      "description": "Triggered when order status changes to Processing",
      "schema": { "type": "object", "properties": {}, "required": [] },
      "capability": "default",
      "accessible": true,
      "state": "available",
      "already_in_rule": false,
      "is_default": true,
      "priority": 1
    }
  ],
  "conditions": [
    {
      "id": "product_type",
      "label": "Product Type",
      "description": "Match orders by product type",
      "schema": {
        "type": "object",
        "properties": {
          "types": { "type": "array", "items": { "type": "string" } },
          "match_all": { "type": "boolean" }
        },
        "required": ["types"]
      },
      "capability": "default",
      "accessible": true
    }
  ],
  "primaryActions": [
    {
      "id": "change_status_to_completed",
      "label": "Change Status to Completed",
      "description": "Changes order status to Completed",
      "capability": "default",
      "accessible": true
    }
  ],
  "secondaryActions": [],
  "meta": {
    "execution_time": 0.123,
    "timestamp": "2026-01-18T14:30:00Z"
  }
}

GET /rule/{id}

Get a specific rule by ID.

curl "https://yoursite.com/wp-json/odcm/v1/rule/123" 
  -u "your-username:xxxx xxxx xxxx xxxx xxxx xxxx"

Response:

{
  "trigger": { "id": "order_processing", "settings": {} },
  "conditions": [
    { "id": "product_type", "settings": { "types": ["virtual", "downloadable"], "match_all": false } }
  ],
  "primaryAction": {
    "id": "change_status_to_completed",
    "settings": { "send_emails": true, "update_stock": false }
  },
  "secondaryActions": []
}

PUT /rule/{id}

Save a rule’s data.

Request body:

{
  "rule": {
    "trigger": { "id": "order_processing", "settings": {} },
    "conditions": [
      { "id": "product_type", "settings": { "types": ["virtual"], "match_all": false } }
    ],
    "primaryAction": {
      "id": "change_status_to_completed",
      "settings": { "send_emails": true, "update_stock": false }
    },
    "secondaryActions": []
  },
  "audit": {
    "action": "rule_modified",
    "user_context": { "user_agent": "...", "page_url": "..." }
  }
}
curl -X PUT "https://yoursite.com/wp-json/odcm/v1/rule/123" 
  -H "Content-Type: application/json" 
  -u "your-username:xxxx xxxx xxxx xxxx xxxx xxxx" 
  -d '{"rule": {...}, "audit": {...}}'

Response:

{
  "success": true,
  "message": "Rule saved successfully",
  "rule_id": 123,
  "audit_logged": true
}

GET /rule-builder/search-content

Search for dynamic content to populate condition pickers (products, categories, etc.).

Parameters:

  • source (string, required) – see table below
  • search (string, optional) – search query
  • limit (int, optional) – max results (default: 50, max: 100)

All sources return {results: [...], meta: {source, search_term, count, execution_time}}. Every result item has value (the ID/key to store in settings), label (display string), and meta (extra fields per source).

sourcevaluemeta fields
productsproduct ID (string)id, title, sku
categoriesterm ID (string)id, name, slug, count
product_tagsterm ID (string)id, name, slug, count
postspost ID (string)id, title, type, status
usersrole key (string)key, name – returns roles, not individual users
order_statusesstatus key e.g. wc-processingkey, name
payment_methodsgateway IDid, title, enabled
shipping_methodsmethod IDid, title, description
curl "https://yoursite.com/wp-json/odcm/v1/rule-builder/search-content?source=products&search=shirt&limit=10" 
  -u "your-username:xxxx xxxx xxxx xxxx xxxx xxxx"

Response (source=products):

{
  "results": [
    { "value": "456", "label": "T-Shirt (SKU: TS-100) (ID: 456)", "meta": { "id": 456, "title": "T-Shirt", "sku": "TS-100" } }
  ],
  "meta": { "source": "products", "search_term": "shirt", "count": 1, "execution_time": 0.045 }
}

Response (source=order_statuses):

{
  "results": [
    { "value": "wc-processing", "label": "Processing (wc-processing)", "meta": { "key": "wc-processing", "name": "Processing" } }
  ],
  "meta": { "source": "order_statuses", "search_term": "", "count": 8, "execution_time": 0.002 }
}

Error responses

Errors follow the WordPress REST standard format:

{ "code": "error_code", "message": "Human-readable description", "data": { "status": 400 } }
ScenarioHTTPcode
Missing or invalid parameters400rest_missing_callback_param, missing_source
Not authenticated / bad nonce401rest_forbidden
Insufficient capability401rest_forbidden
Rule post not found404(WP default)
Internal error500WP error with status 500

Integration examples

JavaScript – create a rule:

const ruleData = {
  trigger: { id: 'order_processing', settings: {} },
  conditions: [{ id: 'order_total', settings: { operator: '>=', amount: 100 } }],
  primaryAction: { id: 'change_status_to_completed', settings: {} },
  secondaryActions: []
};

wp.apiFetch({
  path: '/odcm/v1/rule/123',
  method: 'PUT',
  data: { rule: ruleData, audit: { action: 'rule_created' } }
}).then(response => {
  console.log('Saved rule ID:', response.rule_id);
});

PHP – internal request:

$request  = new WP_REST_Request('GET', '/odcm/v1/rule-builder/components');
$response = rest_do_request($request);
if ($response->is_success()) {
    $components = $response->get_data();
}

Best practices

  • Cache component discovery data – it changes infrequently.
  • Implement debouncing for search-as-you-type features using search-content.
  • Use pagination for large rule sets.