How to Create Data Transformation Rules
Rules automate data transformations as inventory flows through Carfluence. Instead of manually fixing data issues, rules handle them automatically on every sync.
Rule Structure
Every rule has two parts:
- 1Conditions: When should this rule fire?
- 2Actions: What should it do?
Creating a Rule
bash
POST /api/v1/rules
{
"name": "Price Markup for Used Vehicles",
"conditions": [
{"field": "condition", "operator": "equals", "value": "used"},
{"field": "price", "operator": "greater_than", "value": "0"}
],
"actions": [
{"type": "set_field", "field": "internet_price", "value_expr": "price * 0.95"}
]
}Condition Operators
| Operator | Example | Description |
|---|---|---|
equals | {"field": "make", "operator": "equals", "value": "Toyota"} | Exact string match |
not_equals | {"field": "status", "operator": "not_equals", "value": "sold"} | Does not match |
contains | {"field": "model", "operator": "contains", "value": "F-150"} | String contains |
in | {"field": "make", "operator": "in", "value": "BMW,Audi,Mercedes-Benz"} | Value in list |
greater_than | {"field": "price", "operator": "greater_than", "value": "50000"} | Numeric comparison |
less_than | {"field": "mileage", "operator": "less_than", "value": "10000"} | Numeric comparison |
is_empty | {"field": "interior_color", "operator": "is_empty"} | Field is null/empty |
is_not_empty | {"field": "photos", "operator": "is_not_empty"} | Field has a value |
Action Types
| Type | Description |
|---|---|
set_field | Set a field to a static value |
set_field (with value_expr) | Set a field using a calculated expression |
Common Use Cases
1. Set internet price to 5% below list price:
json
{
"conditions": [{"field": "price", "operator": "greater_than", "value": "0"}],
"actions": [{"type": "set_field", "field": "internet_price", "value_expr": "price * 0.95"}]
}2. Flag old inventory:
json
{
"conditions": [{"field": "days_on_lot", "operator": "greater_than", "value": "90"}],
"actions": [{"type": "set_field", "field": "tags", "value": "aged-inventory"}]
}3. Standardize body styles:
json
{
"conditions": [{"field": "body_style", "operator": "in", "value": "4DR,4-Door,Four Door"}],
"actions": [{"type": "set_field", "field": "body_style", "value": "Sedan"}]
}Testing Before Activating
Always test rules before they run on real data:
bash
POST /api/v1/rules/:id/test
{
"vehicle": {
"vin": "TEST12345678901",
"make": "Honda",
"price": "30000",
"condition": "used"
}
}Managing Rules
bash
# List all rules
GET /api/v1/rules
# Update a rule
PATCH /api/v1/rules/:id
# Delete a rule
DELETE /api/v1/rules/:idRules execute in creation order. If two rules conflict, the last one wins.