API ReferenceEnrichment

Enrichment API

Configure and manage enrichment rules that automatically transform, validate, and route leads.

Base URL: https://api.ledly.io/api

Authentication: Bearer Token (see Authentication)


Overview

The Enrichment API allows you to programmatically manage enrichment rules that process leads. Rules can:

  • Set default field values
  • Transform data (uppercase, lowercase, format phone numbers)
  • Calculate derived fields
  • Reject invalid leads
  • Route leads based on conditions
  • Trigger external webhooks

List Enrichment Rules

Retrieve all enrichment rules for your organization.

Endpoint: GET /api/enrichment/rules

Request

curl -H "Authorization: Bearer your_token" \
  https://api.ledly.io/api/enrichment/rules

Response (200 OK)

{
  "data": [
    {
      "id": "rule_abc123",
      "name": "Reject Disposable Emails",
      "description": "Block leads from disposable email providers",
      "priority": 10,
      "enabled": true,
      "conditions": {
        "operator": "OR",
        "rules": [
          {
            "field": "email",
            "operator": "ends_with",
            "value": "@mailinator.com"
          },
          {
            "field": "email",
            "operator": "ends_with",
            "value": "@tempmail.com"
          }
        ]
      },
      "actions": [
        {
          "type": "reject",
          "reason": "Disposable email address not allowed"
        }
      ],
      "created_at": "2024-12-01T10:00:00Z",
      "updated_at": "2024-12-15T14:30:00Z"
    },
    {
      "id": "rule_def456",
      "name": "Set MBA Program Code",
      "description": "Auto-assign program code for MBA leads",
      "priority": 20,
      "enabled": true,
      "conditions": {
        "operator": "AND",
        "rules": [
          {
            "field": "program_interest",
            "operator": "contains",
            "value": "MBA"
          }
        ]
      },
      "actions": [
        {
          "type": "set_field",
          "field": "program_code",
          "value": "MBA-ONLINE"
        },
        {
          "type": "set_field",
          "field": "assigned_rep",
          "value": "[email protected]"
        }
      ],
      "created_at": "2024-12-01T10:00:00Z",
      "updated_at": "2024-12-01T10:00:00Z"
    }
  ]
}

Get Enrichment Rule

Retrieve details for a specific rule.

Endpoint: GET /api/enrichment/rules/:id

Request

curl -H "Authorization: Bearer your_token" \
  https://api.ledly.io/api/enrichment/rules/rule_abc123

Response (200 OK)

{
  "data": {
    "id": "rule_abc123",
    "name": "Reject Disposable Emails",
    "description": "Block leads from disposable email providers",
    "priority": 10,
    "enabled": true,
    "conditions": {
      "operator": "OR",
      "rules": [
        {
          "field": "email",
          "operator": "ends_with",
          "value": "@mailinator.com"
        }
      ]
    },
    "actions": [
      {
        "type": "reject",
        "reason": "Disposable email address not allowed"
      }
    ],
    "stats": {
      "total_matches": 1523,
      "last_30_days": 47
    },
    "created_at": "2024-12-01T10:00:00Z",
    "updated_at": "2024-12-15T14:30:00Z"
  }
}

Create Enrichment Rule

Create a new enrichment rule.

Endpoint: POST /api/enrichment/rules

Request

curl -X POST https://api.ledly.io/api/enrichment/rules \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Auto-assign California leads",
    "description": "Route California leads to West Coast team",
    "priority": 50,
    "enabled": true,
    "conditions": {
      "operator": "AND",
      "rules": [
        {
          "field": "state",
          "operator": "equals",
          "value": "California"
        }
      ]
    },
    "actions": [
      {
        "type": "set_field",
        "field": "region",
        "value": "West Coast"
      },
      {
        "type": "set_field",
        "field": "assigned_team",
        "value": "[email protected]"
      }
    ]
  }'

Request Body

FieldTypeRequiredDescription
namestringYesRule name
descriptionstringNoRule description
priorityintegerYesExecution order (lower = earlier)
enabledbooleanNoEnable rule (default: true)
conditionsobjectYesCondition configuration
actionsarrayYesActions to execute

Response (201 Created)

{
  "data": {
    "id": "rule_xyz789",
    "name": "Auto-assign California leads",
    "priority": 50,
    "enabled": true,
    "created_at": "2024-12-25T12:00:00Z"
  }
}

Update Enrichment Rule

Update an existing rule.

Endpoint: PATCH /api/enrichment/rules/:id

Request

curl -X PATCH https://api.ledly.io/api/enrichment/rules/rule_abc123 \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false,
    "priority": 15
  }'

Response (200 OK)

{
  "data": {
    "id": "rule_abc123",
    "name": "Reject Disposable Emails",
    "priority": 15,
    "enabled": false,
    "updated_at": "2024-12-25T12:30:00Z"
  }
}

Delete Enrichment Rule

Delete a rule permanently.

Endpoint: DELETE /api/enrichment/rules/:id

Request

curl -X DELETE https://api.ledly.io/api/enrichment/rules/rule_abc123 \
  -H "Authorization: Bearer your_token"

Response (204 No Content)


Test Enrichment Rules

Test rules against sample lead data without creating a lead.

Endpoint: POST /api/enrichment/test

Request

curl -X POST https://api.ledly.io/api/enrichment/test \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "lead_data": {
      "email": "[email protected]",
      "first_name": "John",
      "last_name": "Doe",
      "state": "California"
    }
  }'

Response (200 OK)

{
  "results": [
    {
      "rule_id": "rule_abc123",
      "rule_name": "Reject Disposable Emails",
      "priority": 10,
      "matched": true,
      "actions_taken": [
        {
          "type": "reject",
          "reason": "Disposable email address not allowed"
        }
      ],
      "processing_stopped": true
    },
    {
      "rule_id": "rule_xyz789",
      "rule_name": "Auto-assign California leads",
      "priority": 50,
      "matched": false,
      "reason": "Processing stopped by earlier rule"
    }
  ],
  "final_outcome": "rejected",
  "rejection_reason": "Disposable email address not allowed"
}

Condition Operators

Comparison Operators

OperatorDescriptionExample
equalsExact matchstate equals "California"
not_equalsNot equalstatus not_equals "rejected"
containsPartial matchemail contains "@edu"
not_containsDoesn’t containemail not_contains "@gmail"
starts_withPrefix matchphone starts_with "+1"
ends_withSuffix matchemail ends_with ".edu"
is_emptyNo valuecompany is_empty
is_not_emptyHas valuephone is_not_empty
greater_thanNumeric >age greater_than 18
less_thanNumeric less thanscore less_than 50
greater_than_or_equalNumeric >=years_experience >= 3
less_than_or_equalNumeric ≤age <= 65
inOne of liststate in ["CA","NY","TX"]
not_inNot in listsource not_in ["spam","bot"]
matches_regexRegex matchemail matches ".*@university\\.edu"

Logical Operators

{
  "operator": "AND",
  "rules": [
    { "field": "state", "operator": "equals", "value": "California" },
    { "field": "program", "operator": "contains", "value": "MBA" }
  ]
}
{
  "operator": "OR",
  "rules": [
    { "field": "email", "operator": "ends_with", "value": "@mailinator.com" },
    { "field": "email", "operator": "ends_with", "value": "@tempmail.com" }
  ]
}

Nested Conditions

{
  "operator": "AND",
  "rules": [
    {
      "field": "state",
      "operator": "equals",
      "value": "California"
    },
    {
      "operator": "OR",
      "rules": [
        { "field": "program", "operator": "contains", "value": "MBA" },
        { "field": "program", "operator": "contains", "value": "Business" }
      ]
    }
  ]
}

Action Types

Set Field

Set a field to a static value:

{
  "type": "set_field",
  "field": "program_code",
  "value": "MBA-ONLINE"
}

Transform Field

Transform existing field value:

{
  "type": "transform",
  "field": "email",
  "transformation": "lowercase"
}

Available Transformations:

  • uppercase - Convert to uppercase
  • lowercase - Convert to lowercase
  • titlecase - Title Case
  • trim - Remove whitespace
  • phone_format - Format phone number
  • email_domain - Extract domain from email

Calculate Field

Calculate value from other fields:

{
  "type": "calculate",
  "field": "full_name",
  "formula": "{{first_name}} {{last_name}}"
}

Reject Lead

Reject lead and stop processing:

{
  "type": "reject",
  "reason": "Disposable email address not allowed"
}

Flag for Review

Mark lead for manual review:

{
  "type": "flag",
  "reason": "Suspicious data pattern",
  "severity": "high"
}

Trigger Webhook

Call external webhook:

{
  "type": "webhook",
  "url": "https://api.example.com/enrich",
  "method": "POST",
  "payload": {
    "email": "{{email}}",
    "source": "{{source}}"
  }
}

Stop Processing

Stop rule execution:

{
  "type": "stop_processing"
}

Custom Fields

List Custom Fields

Endpoint: GET /api/enrichment/custom-fields

curl -H "Authorization: Bearer your_token" \
  https://api.ledly.io/api/enrichment/custom-fields

Response:

{
  "data": [
    {
      "id": "field_abc123",
      "name": "preferred_start",
      "label": "Preferred Start Date",
      "type": "string",
      "required": false,
      "default_value": null,
      "validation": {
        "pattern": "^(Spring|Summer|Fall|Winter) \\d{4}$"
      },
      "created_at": "2024-12-01T10:00:00Z"
    },
    {
      "id": "field_def456",
      "name": "years_experience",
      "label": "Years of Experience",
      "type": "number",
      "required": false,
      "validation": {
        "min": 0,
        "max": 50
      },
      "created_at": "2024-12-01T10:00:00Z"
    }
  ]
}

Create Custom Field

Endpoint: POST /api/enrichment/custom-fields

curl -X POST https://api.ledly.io/api/enrichment/custom-fields \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "education_level",
    "label": "Education Level",
    "type": "string",
    "required": false,
    "validation": {
      "enum": ["High School", "Associates", "Bachelors", "Masters", "Doctorate"]
    }
  }'

Response (201 Created):

{
  "data": {
    "id": "field_xyz789",
    "name": "education_level",
    "label": "Education Level",
    "type": "string",
    "created_at": "2024-12-25T12:00:00Z"
  }
}

Lookup Tables

List Lookup Tables

Endpoint: GET /api/enrichment/lookup-tables

curl -H "Authorization: Bearer your_token" \
  https://api.ledly.io/api/enrichment/lookup-tables

Create Lookup Table

Endpoint: POST /api/enrichment/lookup-tables

curl -X POST https://api.ledly.io/api/enrichment/lookup-tables \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "zip_to_state",
    "description": "Map ZIP codes to states",
    "mappings": {
      "90210": "California",
      "10001": "New York",
      "75001": "Texas"
    }
  }'

Use in Rules

{
  "type": "lookup",
  "target_field": "state",
  "table_name": "zip_to_state",
  "lookup_field": "zip_code"
}

Rule Priority

Rules execute in priority order (lowest number first). Manage priority carefully:

Reorder Rules

Endpoint: POST /api/enrichment/rules/reorder

curl -X POST https://api.ledly.io/api/enrichment/rules/reorder \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "rules": [
      { "id": "rule_1", "priority": 10 },
      { "id": "rule_2", "priority": 20 },
      { "id": "rule_3", "priority": 30 }
    ]
  }'

Export and Import Rules

Export Rules

Endpoint: GET /api/enrichment/rules/export

curl -H "Authorization: Bearer your_token" \
  https://api.ledly.io/api/enrichment/rules/export > rules.json

Import Rules

Endpoint: POST /api/enrichment/rules/import

curl -X POST https://api.ledly.io/api/enrichment/rules/import \
  -H "Authorization: Bearer your_token" \
  -H "Content-Type: application/json" \
  -d @rules.json
⚠️

Importing rules adds to existing rules. It does not replace them.


Examples

Complete Rule Management

// 1. Create a rule
const createResponse = await fetch('https://api.ledly.io/api/enrichment/rules', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_token',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Set Default Source',
    priority: 100,
    enabled: true,
    conditions: {
      operator: 'AND',
      rules: [
        { field: 'source', operator: 'is_empty' }
      ]
    },
    actions: [
      { type: 'set_field', field: 'source', value: 'website' }
    ]
  }),
});
 
const { data: rule } = await createResponse.json();
 
// 2. Test the rule
const testResponse = await fetch('https://api.ledly.io/api/enrichment/test', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your_token',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    lead_data: {
      email: '[email protected]',
      first_name: 'Test'
    }
  }),
});
 
const testResults = await testResponse.json();
console.log('Test results:', testResults);
 
// 3. Update rule priority
await fetch(`https://api.ledly.io/api/enrichment/rules/${rule.id}`, {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer your_token',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ priority: 50 }),
});