LendWorksLendWorksDocs

SDKs

Official TypeScript SDK and webhook verification package for LendWorks integrations.

TypeScript SDK

The official Node.js SDK provides type-safe access to all LendWorks API endpoints.

Installation

npm install @lendworks/sdk-node

The SDK is ESM-only and requires Node.js 18+.

Initialization

import { LendWorksClient } from '@lendworks/sdk-node'

const client = new LendWorksClient({
  apiKey: process.env.LENDWORKS_API_KEY,
})

Usage Examples

const { data: leads, meta } = await client.leads.list({
  limit: 50,
  search: 'technology',
})

console.log(`Found ${meta.total} matching leads`)
for (const lead of leads) {
  console.log(`${lead.attributes.businessName} — ${lead.attributes.priority}`)
}

Create a Lead with Idempotency

const { data: lead } = await client.leads.create(
  {
    businessName: 'Acme Corp',
    contactFirstName: 'Jane',
    contactLastName: 'Doe',
    email: 'jane@acme.com',
    requestedAmount: '250000',
    source: 'api',
  },
  { idempotencyKey: crypto.randomUUID() }
)

console.log(`Created: ${lead.id}`)

Update a Lead

const { data: updated } = await client.leads.update(
  'd290f1ee-6c54-4b01-90e6-d701748f0851',
  { priority: 'urgent', requestedAmount: '500000' }
)

Get Applications

const { data: apps } = await client.applications.list({ limit: 20 })

for (const app of apps) {
  console.log(`${app.attributes.client.businessName} — ${app.attributes.stage.label}`)
}

View Analytics

const { data: kpis } = await client.analytics.kpis()
console.log(`Deals funded this month: ${kpis.attributes.dealsFunded.current}`)
console.log(`Funded amount: $${kpis.attributes.fundedAmount.current.toLocaleString()}`)

const { data: leaderboard } = await client.analytics.leaderboard({
  metric: 'commission_earned',
  period: 'this_month',
  limit: 5,
})

Iterate All Pages

let page = 1
let hasMore = true
const allLeads = []

while (hasMore) {
  const result = await client.leads.list({ page, limit: 100 })
  allLeads.push(...result.data)
  hasMore = result.meta.hasMore
  page++
}

console.log(`Total leads: ${allLeads.length}`)

Error Handling

import { LendWorksClient, LendWorksError } from '@lendworks/sdk-node'

try {
  await client.leads.create({ email: 'invalid' })
} catch (error) {
  if (error instanceof LendWorksError) {
    console.error(`${error.code}: ${error.message}`)
    console.error(`Request ID: ${error.requestId}`)

    if (error.code === 'RATE_LIMIT_EXCEEDED') {
      const retryAfter = error.detail?.retryAfter || 60
      await new Promise(r => setTimeout(r, retryAfter * 1000))
    }
  }
}

Available Resources

ResourceMethods
client.leadslist(), get(), create(), update()
client.applicationslist(), get()
client.lenderslist(), get()
client.fundedDealslist(), get()
client.commissionslist(), summary()
client.analyticskpis(), pipeline(), leaderboard()
client.automationslist(), trigger(), cancel()
client.dialersubmitEvent(), updatePresence(), submitDisposition(), agents()

Webhook Verification

A lightweight package for verifying webhook signatures. Install separately to keep your webhook handler lean.

Installation

npm install @lendworks/webhook-verify

Also ESM-only, Node.js 18+.

Usage

import { createVerifier } from '@lendworks/webhook-verify'

const verifier = createVerifier({
  secret: process.env.WEBHOOK_SECRET,
})

// Verify a webhook payload
const event = verifier.verify(rawBody, {
  'x-webhook-signature': headers['x-webhook-signature'],
  'x-webhook-id': headers['x-webhook-id'],
  'x-webhook-timestamp': headers['x-webhook-timestamp'],
})

// event.event  → 'lead.created'
// event.data   → { leadId: '...', orgId: '...' }
// event.id     → 'evt_550e8400-...'

Verification Checks

The verifier performs:

  1. Timestamp validation — Rejects events older than 5 minutes to prevent replay attacks
  2. Signature verification — HMAC-SHA256 with constant-time comparison
  3. Payload parsing — Returns a typed event object

See the Webhooks guide for framework-specific examples (Express, Next.js).


REST API (No SDK)

If you prefer to call the API directly without the SDK:

const BASE_URL = 'https://api.lend.works/v1'
const API_KEY = process.env.LENDWORKS_API_KEY

async function lendworks(path: string, options: RequestInit = {}) {
  const res = await fetch(`${BASE_URL}${path}`, {
    ...options,
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
      ...options.headers,
    },
  })

  if (!res.ok) {
    const error = await res.json()
    throw new Error(`${res.status}: ${error.errors?.[0]?.message || 'Unknown error'}`)
  }

  return res.json()
}

// Usage
const leads = await lendworks('/leads?limit=10')
const lead = await lendworks('/leads', {
  method: 'POST',
  body: JSON.stringify({ businessName: 'Acme Corp' }),
})