> For the complete documentation index, see [llms.txt](https://integrate.lexamica.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integrate.lexamica.com/example-integrations/1.-lead-form-submission.md).

# Lead Form Submission

Send cases from a web form into Lexamica.

***

## 🎯 Overview

> **📌 TL;DR**
>
> This is the simplest integration: capture leads from a form, send them to Lexamica, and let the Relay Engine find a partner firm. No webhooks, no polling—just one API call per case.

**This guide is for you if:**

* You have a web form that captures case/lead information
* You want cases to automatically enter Lexamica's Relay Engine
* You don't need real-time updates back (you'll check status in-platform)

**What you'll build:**

* A Case mapping to translate your form fields
* An API call that sends cases to Lexamica

**What this does NOT cover:**

* Receiving notifications when cases are matched or accepted
* Responding to invitations
* Uploading files

For those features, see [Originator: Full Integration with Webhooks](/example-integrations/3a.-originator-full-webhook.md).

***

## 📖 Key Terms

| Term             | Definition                                                               |
| ---------------- | ------------------------------------------------------------------------ |
| **Mapping**      | Configuration that translates your field names to Lexamica's field names |
| **Relay Engine** | Lexamica's automatic matching system that routes cases to partner firms  |
| **Public Key**   | API key used for sending data to Lexamica                                |

***

## ⚙️ Architecture

```
Lead Form Integration
─────────────────────

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│   Web Form      │────▶│   Your Server   │────▶│    Lexamica     │
│                 │     │                 │     │                 │
│ User submits    │     │ POST to         │     │ Case enters     │
│ case details    │     │ /case/send      │     │ Relay Engine    │
└─────────────────┘     └─────────────────┘     └─────────────────┘
                                │
                                ▼
                        ┌─────────────────┐
                        │  Store case_id  │
                        │  for reference  │
                        └─────────────────┘
```

> **🎯 Key Takeaway**
>
> One API call sends the case. Lexamica handles everything else—matching, invitations, and tracking.

***

## 📋 Prerequisites

**Credentials:**

* [ ] Organization ID, Public Key, and Private Key from Lexamica

**Foundational Docs:**

* [ ] [Organizations and Authentication](/1.-organizations-and-authentication.md) — understand your API keys
* [ ] [Mapping Engine](/2.-mapping-engine.md) — how field transformations work
* [ ] [Inbound Webhooks](/3.-inbound-webhooks.md)— sending data to Lexamica

***

## 💡 Step-by-Step Implementation

### Step 1: Create Your Case Mapping

First, create a mapping that translates your form fields to Lexamica's Case fields.

**Request:**

```bash
curl -X POST \
  "https://integration.lexamica.com/organization/{orgId}/mapping/create" \
  -H "Authorization: Bearer your_private_key" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Lead Form Mapping",
    "modelName": "Case",
    "fieldMappings": [
      {
        "lexamicaField": "client.firstName",
        "foreignField": "first_name",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "client.lastName",
        "foreignField": "last_name",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "client.email",
        "foreignField": "email",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "client.phoneNumber",
        "foreignField": "phone",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "caseType",
        "foreignField": "case_type",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "incident.date",
        "foreignField": "incident_date",
        "lexamicaFieldType": "Date",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "incident.address.state",
        "foreignField": "incident_state",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      },
      {
        "lexamicaField": "incident.synopsis",
        "foreignField": "description",
        "lexamicaFieldType": "String",
        "foreignFieldType": "String"
      }
    ]
  }'
```

**Response:**

```json
{
  "_id": "64f1a2b3c4d5e6f7a8b9c0d2",
  "label": "Lead Form Mapping",
  "modelName": "Case",
  "fieldMappings": [...],
  "created": "2026-01-15T10:30:00.000Z"
}
```

> **💡 Tip:** Save the `_id` from the response—this is your Mapping ID that you'll use for every case submission.

### Step 2: Send Cases to Lexamica

When your form is submitted, send the case to Lexamica.

**Request:**

```bash
curl -X POST \
  "https://integration.lexamica.com/organization/{orgId}/inbound-webhooks/case/{mapId}/send?Key=your_public_key" \
  -H "Content-Type: application/json" \
  -d '{
    "first_name": "Jane",
    "last_name": "Smith",
    "email": "jane.smith@example.com",
    "phone": "555-123-4567",
    "case_type": "Personal Injury",
    "incident_date": "2026-01-10",
    "incident_state": "CA",
    "description": "Rear-end collision on Highway 101."
  }'
```

**Response:**

```json
{
  "case_id": "64f1a2b3c4d5e6f7a8b9c0d3",
  "first_name": "Jane",
  "last_name": "Smith",
  "status": "pending_match",
  "created": "2026-01-15T10:30:00.000Z"
}
```

### Step 3: Store the Case ID

**Always store the returned `case_id`** in your system. This allows you to:

* Look up the case in Lexamica later
* Prevent duplicate submissions
* Correlate if you add webhooks in the future

***

## 🔧 Complete Code Example

### Node.js/Express Implementation

```javascript
const express = require('express');
const axios = require('axios');

const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

// Configuration
const config = {
  orgId: process.env.LEXAMICA_ORG_ID,
  publicKey: process.env.LEXAMICA_PUBLIC_KEY,
  mappingId: process.env.LEXAMICA_CASE_MAPPING_ID,
  baseUrl: 'https://integration.lexamica.com'
};

// Form submission endpoint
app.post('/submit-lead', async (req, res) => {
  try {
    // Map form data to your field names
    const caseData = {
      first_name: req.body.firstName,
      last_name: req.body.lastName,
      email: req.body.email,
      phone: req.body.phone,
      case_type: req.body.caseType,
      incident_date: req.body.incidentDate,
      incident_state: req.body.incidentState,
      description: req.body.description
    };

    // Send to Lexamica
    const response = await axios.post(
      `${config.baseUrl}/organization/${config.orgId}/inbound-webhooks/case/${config.mappingId}/send`,
      caseData,
      {
        headers: { 'Content-Type': 'application/json' },
        params: { Key: config.publicKey }
      }
    );

    // Store the Lexamica case ID (implement your storage logic)
    const lexamicaCaseId = response.data.case_id;
    console.log(`Case created in Lexamica: ${lexamicaCaseId}`);
    
    // Optionally store in your database
    // await saveToDatabase({ formData: req.body, lexamicaCaseId });

    // Redirect or respond to user
    res.json({
      success: true,
      message: 'Your case has been submitted successfully.',
      referenceId: lexamicaCaseId
    });

  } catch (error) {
    console.error('Failed to submit case:', error.response?.data || error.message);
    
    res.status(500).json({
      success: false,
      message: 'There was an error submitting your case. Please try again.'
    });
  }
});

app.listen(3000, () => {
  console.log('Lead form server running on port 3000');
});
```

### HTML Form Example

```html
<form action="/submit-lead" method="POST">
  <h2>Request a Free Consultation</h2>
  
  <label for="firstName">First Name *</label>
  <input type="text" name="firstName" required>
  
  <label for="lastName">Last Name *</label>
  <input type="text" name="lastName" required>
  
  <label for="email">Email</label>
  <input type="email" name="email">
  
  <label for="phone">Phone *</label>
  <input type="tel" name="phone" required>
  
  <label for="caseType">Type of Case *</label>
  <select name="caseType" required>
    <option value="">Select...</option>
    <option value="Personal Injury">Personal Injury</option>
    <option value="Workers Compensation">Workers Compensation</option>
    <option value="Medical Malpractice">Medical Malpractice</option>
  </select>
  
  <label for="incidentDate">Date of Incident *</label>
  <input type="date" name="incidentDate" required>
  
  <label for="incidentState">State Where Incident Occurred *</label>
  <select name="incidentState" required>
    <option value="">Select...</option>
    <option value="CA">California</option>
    <option value="TX">Texas</option>
    <option value="FL">Florida</option>
    <!-- Add more states -->
  </select>
  
  <label for="description">Describe What Happened *</label>
  <textarea name="description" rows="4" required></textarea>
  
  <button type="submit">Submit Case</button>
</form>
```

***

## ❓ FAQ

### ❓ "What fields are required?"

**📝 Full Answer:** For the `/case/{mapId}/send` endpoint, your mapping must provide:

* `client.firstName`
* `client.lastName`
* `client.phoneNumber`
* `caseType`
* `incident.date`
* `incident.address.state`
* `incident.synopsis`

`client.email` is optional but recommended.

***

### ❓ "What happens after I submit?"

**📝 Full Answer:**

1. The case enters Lexamica's Relay Engine
2. Relay finds matching partner firms based on case type and location
3. Invitations are sent to potential handlers
4. You can check the case status by logging into the Lexamica platform

To get automated updates, see [Originator: Full Integration with Webhooks](/example-integrations/3a.-originator-full-webhook.md)

***

### ❓ "How do I prevent duplicate submissions?"

**🔍 Quick Check:**

* Store the Lexamica `case_id` after successful submission
* Check if you've already submitted this lead before sending

**📝 Full Answer:**

```javascript
async function submitCase(formData) {
  // Check if already submitted (using your own ID or hash)
  const existingCase = await findExistingSubmission(formData.email, formData.phone);
  if (existingCase?.lexamica_case_id) {
    return { alreadySubmitted: true, caseId: existingCase.lexamica_case_id };
  }
  
  // Submit to Lexamica
  const result = await sendToLexamica(formData);
  
  // Store immediately after success
  await saveSubmission(formData, result.case_id);
  
  return result;
}
```

***

## 🔧 Troubleshooting

**"400 Bad Request - Missing required field"**

* Check that your mapping includes all required fields
* Verify the form data is being sent with the expected field names

**"401 Unauthorized"**

* Verify your Public Key is correct
* Check that it's being passed as `?Key=...` or in the Authorization header

**"404 Not Found"**

* Verify your Organization ID and Mapping ID are correct
* Ensure the mapping exists (use GET `/mapping` to list mappings)

***

## ➡️ Next Steps

Once your basic form integration is working:

* **Want updates when cases are matched?** See [Originator: Full Integration with Webhooks](/example-integrations/3a.-originator-full-webhook.md)
* **Need to attach files?** See [File Operations](/example-integrations/apx-1.-file-operations.md)
* **Importing existing cases?** See [Import Existing Cases with Webhooks](/example-integrations/5a.-import-existing-webhook.md)

***

*Last updated: January 2026*
