Quick Start
Getting Started with LEX
Send your first LEX message in under 5 minutes. Choose your language, install the library, and integrate with any endpoint that speaks LEX.
Install the Library
Libraries are compiled from the same Haxe source, providing identical validation rules and APIs across all four languages.
# npm
npm install @lexstandard/lex-js
# or yarn
yarn add @lexstandard/lex-js
# or use the pre-built bundle directly
# download from lexstandard.org/libraries
# pip
pip install lexstandard
# or use the pre-built module directly
# download from lexstandard.org/libraries
<!-- Maven -->
<dependency>
<groupId>io.lexstandard</groupId>
<artifactId>lex-java</artifactId>
<version>1.0.0</version>
</dependency>
// Gradle
implementation 'io.lexstandard:lex-java:1.0.0'
// or add the jar from lexstandard.org/libraries to classpath
# NuGet
dotnet add package LexStandard
# or add the DLL from lexstandard.org/libraries to your project
Build Your First Lead Message
Every LEX message has the same envelope: a header with routing metadata and a payload with message-specific content.
const { LexClient } = require('@lexstandard/lex-js');
const client = new LexClient({
senderId: 'DEALER-001',
receiverId: 'MANUFACTURER-ABC',
});
const lead = client.createLead({
status: 'EXPRESSED_INTEREST',
customer: {
firstName: 'Jane',
lastName: 'Smith',
email: 'jane.smith@example.com',
phone: '+13125559876',
},
desiredProduct: {
make: 'Toyota',
model: 'Camry',
year: 2026,
},
});
from lex_client import LexClient
client = LexClient(
sender_id="DEALER-001",
receiver_id="MANUFACTURER-ABC",
)
lead = client.create_lead(
status="EXPRESSED_INTEREST",
customer={
"first_name": "Jane",
"last_name": "Smith",
"email": "jane.smith@example.com",
"phone": "+13125559876",
},
desired_product={
"make": "Toyota",
"model": "Camry",
"year": 2026,
},
)
import io.lex.LexClient;
import io.lex.model.*;
LexClient client = new LexClient.Builder()
.senderId("DEALER-001")
.receiverId("MANUFACTURER-ABC")
.build();
LeadMessage lead = new LeadMessage.Builder()
.status("EXPRESSED_INTEREST")
.customer(new Customer.Builder()
.firstName("Jane")
.lastName("Smith")
.email("jane.smith@example.com")
.phone("+13125559876")
.build())
.build();
using LexStandard;
using LexStandard.Models;
var client = new LexClient(new LexClientOptions {
SenderId = "DEALER-001",
ReceiverId = "MANUFACTURER-ABC",
});
var lead = new LeadMessage {
Status = LeadStatus.ExpressedInterest,
Customer = new Customer {
FirstName = "Jane",
LastName = "Smith",
Email = "jane.smith@example.com",
Phone = "+13125559876",
},
};
Validate Before Sending
The validation engine runs three layers: schema validation, business rule validation, and security checks. Always validate locally before sending to any endpoint.
const result = client.validate(lead);
if (!result.valid) {
result.errors.forEach(err => {
console.error(`[${err.severity}] ${err.field}: ${err.message}`);
// e.g. [CRITICAL] lead.customer.email: INVALID_EMAIL_FORMAT
});
}
// result shape
{
valid: false,
errors: [{ field: 'lead.customer.email', code: 'INVALID_EMAIL_FORMAT',
message: 'Email does not match RFC 5322', severity: 'CRITICAL',
layer: 'BUSINESS_RULES' }]
}
result = client.validate(lead)
if not result.valid:
for err in result.errors:
print(f"[{err['severity']}] {err['field']}: {err['message']}")
# e.g. [CRITICAL] lead.customer.email: INVALID_EMAIL_FORMAT
# result shape
{
"valid": False,
"errors": [{ "field": "lead.customer.email", "code": "INVALID_EMAIL_FORMAT",
"message": "Email does not match RFC 5322", "severity": "CRITICAL",
"layer": "BUSINESS_RULES" }]
}
ValidationResult result = client.validate(lead);
if (!result.isValid()) {
for (ValidationError err : result.getErrors()) {
System.err.printf("[%s] %s: %s%n",
err.getSeverity(), err.getField(), err.getMessage());
// e.g. [CRITICAL] lead.customer.email: INVALID_EMAIL_FORMAT
}
}
// ValidationResult methods
result.isValid(); // false
err.getField(); // "lead.customer.email"
err.getCode(); // "INVALID_EMAIL_FORMAT"
err.getSeverity(); // "CRITICAL"
err.getLayer(); // "BUSINESS_RULES"
var result = client.Validate(lead);
if (!result.Valid) {
foreach (var err in result.Errors) {
Console.Error.WriteLine($"[{err.Severity}] {err.Field}: {err.Message}");
// e.g. [CRITICAL] lead.customer.email: INVALID_EMAIL_FORMAT
}
}
// ValidationResult properties
result.Valid // false
err.Field // "lead.customer.email"
err.Code // "INVALID_EMAIL_FORMAT"
err.Severity // "CRITICAL"
err.Layer // "BUSINESS_RULES"
Layer 1: Schema
Required fields, data types, enum values, and structural constraints.
Layer 2: Business Rules
Email (RFC 5322), phone (E.164), status transitions, financing terms, lead ancestry.
Layer 3: Security
Timestamp bounds (±60s), geographic compliance, PII field protections.
Send and Serialize
LEX messages can be serialized to any of the four supported formats. Deserialize incoming messages with the built-in parsers.
const jsonString = client.serialize(lead, 'json');
const xmlString = client.serialize(lead, 'xml');
const x12String = client.serialize(lead, 'x12');
const edifactStr = client.serialize(lead, 'edifact');
// Parsing incoming messages
const parsed = client.parse(rawJson, 'json');
const result = client.validate(parsed);
// HTTP delivery example (any transport works)
await fetch('https://api.manufacturer.com/lex/v1/leads', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: jsonString,
});
json_str = client.serialize(lead, "json")
xml_str = client.serialize(lead, "xml")
x12_str = client.serialize(lead, "x12")
edifact_str = client.serialize(lead, "edifact")
# Parsing incoming messages
parsed = client.parse(raw_json, "json")
result = client.validate(parsed)
# HTTP delivery example (any transport works)
import requests
requests.post(
"https://api.manufacturer.com/lex/v1/leads",
headers={"Content-Type": "application/json"},
data=json_str,
)
String jsonStr = client.serialize(lead, "json");
String xmlStr = client.serialize(lead, "xml");
String x12Str = client.serialize(lead, "x12");
String edifactStr = client.serialize(lead, "edifact");
// Parsing incoming messages
LexMessage parsed = client.parse(rawJson, "json");
ValidationResult result = client.validate(parsed);
// HTTP delivery example (any transport works)
HttpClient http = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.manufacturer.com/lex/v1/leads"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonStr))
.build();
http.send(req, HttpResponse.BodyHandlers.ofString());
var jsonStr = client.Serialize(lead, "json");
var xmlStr = client.Serialize(lead, "xml");
var x12Str = client.Serialize(lead, "x12");
var edifactStr = client.Serialize(lead, "edifact");
// Parsing incoming messages
var parsed = client.Parse(rawJson, "json");
var result = client.Validate(parsed);
// HTTP delivery example (any transport works)
using var http = new HttpClient();
await http.PostAsync(
"https://api.manufacturer.com/lex/v1/leads",
new StringContent(jsonStr, Encoding.UTF8, "application/json"));
Handle Acknowledgments
Every received LEAD must be responded to with an ACKNOWLEDGMENT message. The ACK may carry a validation result, an error list, or a simple RECEIVED status (Level 1).
const ack = client.createAck({
correlationId: incomingMessage.header.messageId,
status: 'RECEIVED', // or ACCEPTED | REJECTED
validationResult: result, // pass validation outcome
});
await sendTo(incomingMessage.header.senderId, ack);
ack = client.create_ack(
correlation_id=incoming_message["header"]["messageId"],
status="RECEIVED", # or ACCEPTED | REJECTED
validation_result=result, # pass validation outcome
)
await send_to(incoming_message["header"]["senderId"], ack)
AckMessage ack = client.createAck(new AckOptions()
.correlationId(incomingMessage.getHeader().getMessageId())
.status("RECEIVED") // or ACCEPTED | REJECTED
.validationResult(result) // pass validation outcome
.build());
sendTo(incomingMessage.getHeader().getSenderId(), ack);
var ack = client.CreateAck(new AckOptions {
CorrelationId = incomingMessage.Header.MessageId,
Status = "RECEIVED", // or ACCEPTED | REJECTED
ValidationResult = result, // pass validation outcome
});
await SendToAsync(incomingMessage.Header.SenderId, ack);
Level 1 Conformance Requirement
Every LEX receiver MUST send an ACKNOWLEDGMENT for every received LEAD message. Failure to ACK puts your integration below Level 1 conformance.