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.

1

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
2

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,
  },
});
3

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' }]
}

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.

4

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,
});
5

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);

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.

Next Steps