Skip to main content

Leads API

The leads module is the largest in the system. It covers lead CRUD, pipeline stages, scoring, SLA tracking, conversion, and all lead settings.

Core Lead Endpoints

Base path: /leads

POST /leads

Create a new lead. Requires @RequirePermission('leads', 'create').

{
"firstName": "Alice",
"lastName": "Johnson",
"email": "alice@startup.io",
"phone": "+1234567890",
"company": "StartupIO",
"title": "Founder",
"source": "website",
"pipelineId": "pipeline-uuid",
"stageId": "stage-uuid",
"priority": "high",
"estimatedValue": 50000,
"description": "Inbound from pricing page",
"customFields": {
"utm_source": "google",
"company_size": "50-100"
}
}

Response (201):

{
"id": "lead-uuid",
"firstName": "Alice",
"lastName": "Johnson",
"email": "alice@startup.io",
"company": "StartupIO",
"source": "website",
"stageName": "New",
"priority": "high",
"estimatedValue": 50000,
"score": 0,
"createdBy": "user-uuid",
"createdAt": "2025-01-20T10:00:00Z"
}

GET /leads

List leads with filters. Requires @RequirePermission('leads', 'view').

GET /leads?page=1&limit=25&search=alice&stageId=uuid&priority=high&source=website&pipelineId=uuid&assignedTo=uuid

Query Parameters:

ParamTypeDescription
searchstringName, email, company search
stageIdUUIDFilter by pipeline stage
pipelineIdUUIDFilter by pipeline
prioritystringlow, medium, high, critical
sourcestringLead source filter
assignedToUUIDFilter by assigned user
statusstringopen, converted, disqualified
pagenumberPage number
limitnumberItems per page
sortBystringSort column
sortDirstringasc or desc

GET /leads/:id

Get full lead details.

PUT /leads/:id

Update a lead. Requires @RequirePermission('leads', 'edit').

DELETE /leads/:id

Soft-delete a lead. Requires @RequirePermission('leads', 'delete').

POST /leads/check-duplicates

Check for duplicate leads before creation.

{ "email": "alice@startup.io", "phone": "+1234567890" }

Response:

{
"duplicates": [
{ "id": "existing-uuid", "firstName": "Alice", "lastName": "Johnson", "email": "alice@startup.io", "matchField": "email" }
]
}

PUT /leads/bulk-update

Bulk update multiple leads. Requires @RequirePermission('leads', 'edit').

{
"ids": ["uuid-1", "uuid-2", "uuid-3"],
"changes": { "assignedTo": "user-uuid", "priority": "high" }
}

DELETE /leads/bulk-delete

Bulk soft-delete. Requires @RequirePermission('leads', 'delete').

{ "ids": ["uuid-1", "uuid-2"] }

Stage Management

POST /leads/:id/change-stage

Move a lead to a different pipeline stage.

{
"stageId": "target-stage-uuid",
"stageFieldValues": {
"amount": 50000,
"close_date": "2025-03-01"
}
}

POST /leads/:id/disqualify

Disqualify a lead with a reason.

{
"reason": "no_budget",
"notes": "Company confirmed no budget until next fiscal year"
}

Conversion

GET /leads/:id/conversion-check

Pre-check before converting a lead to opportunity/contact/account.

{
"canConvert": true,
"existingContact": null,
"existingAccount": { "id": "account-uuid", "name": "StartupIO" },
"requiredFields": ["estimatedValue"]
}

POST /leads/:id/convert

Convert a lead to opportunity + contact + account.

{
"createContact": true,
"createAccount": true,
"createOpportunity": true,
"accountId": "existing-account-uuid",
"opportunityName": "StartupIO Enterprise Deal",
"opportunityPipelineId": "opp-pipeline-uuid",
"opportunityStageId": "opp-stage-uuid"
}

Response:

{
"contactId": "new-contact-uuid",
"accountId": "existing-account-uuid",
"opportunityId": "new-opp-uuid",
"message": "Lead converted successfully"
}

SLA

GET /leads/sla/summary

SLA compliance summary across all leads.

{
"total": 150,
"withinSla": 130,
"atRisk": 12,
"breached": 8,
"complianceRate": 86.7
}

GET /leads/:id/sla

SLA status for a specific lead.

{
"leadId": "lead-uuid",
"slaPolicy": "Standard Response",
"responseDeadline": "2025-01-20T14:00:00Z",
"status": "at_risk",
"timeRemaining": "1h 30m",
"firstResponseAt": null
}

POST /leads/sla/check-breaches

Trigger an SLA breach check (typically called by cron).

Products

GET /leads/:id/products

[
{ "id": "lp-uuid", "productId": "prod-uuid", "productName": "Enterprise Plan", "quantity": 1, "unitPrice": 5000, "discount": 10, "total": 4500 }
]

POST /leads/:id/products

{ "productId": "prod-uuid", "quantity": 2, "unitPrice": 5000, "discount": 0 }

PUT /leads/:id/products/:productId

DELETE /leads/:id/products/:productId

Team

GET /leads/:id/team

POST /leads/:id/team

{ "userId": "user-uuid", "role": "sales_rep" }

DELETE /leads/:id/team/:userId

Activities, History, Notes, Documents

GET /leads/:id/activities

GET /leads/:id/history

GET /leads/:id/notes

POST /leads/:id/notes

GET /leads/:id/documents


Lead Settings API

Base path: /lead-settings

All settings endpoints require @AdminOnly() for writes.

Pipelines

MethodPathDescription
GET/lead-settings/pipelines?module=leadsList pipelines
POST/lead-settings/pipelinesCreate pipeline
PUT/lead-settings/pipelines/:idUpdate pipeline
DELETE/lead-settings/pipelines/:idDelete pipeline

Stages

MethodPathDescription
GET/lead-settings/stages?module=leads&pipelineId=uuidList stages
POST/lead-settings/stagesCreate stage
PUT/lead-settings/stages/:idUpdate stage
DELETE/lead-settings/stages/:idDelete stage
PUT/lead-settings/stages/reorderReorder stages
GET/lead-settings/stages/:id/fieldsGet stage fields
POST/lead-settings/stages/:id/fieldsAdd stage field
PUT/lead-settings/stages/:id/fields/:fieldIdUpdate stage field
DELETE/lead-settings/stages/:id/fields/:fieldIdDelete stage field

Stage Ownership

MethodPathDescription
GET/lead-settings/stage-ownership/:stageIdGet stage ownership config
PUT/lead-settings/stage-ownership/:stageIdUpdate stage ownership

Field Visibility

MethodPathDescription
GET/lead-settings/field-visibility/:stageIdGet field visibility per stage
PUT/lead-settings/field-visibility/:stageIdUpdate field visibility

Priorities, Sources, Reasons

MethodPathDescription
GET/lead-settings/prioritiesList lead priorities
POST/lead-settings/prioritiesCreate priority
PUT/lead-settings/priorities/:idUpdate priority
DELETE/lead-settings/priorities/:idDelete priority
GET/lead-settings/sourcesList lead sources
POST/lead-settings/sourcesCreate source
GET/lead-settings/disqualification-reasonsList reasons
POST/lead-settings/disqualification-reasonsCreate reason

Scoring

MethodPathDescription
GET/lead-settings/scoring-rulesList scoring rules
POST/lead-settings/scoring-rulesCreate rule
PUT/lead-settings/scoring-rules/:idUpdate rule
DELETE/lead-settings/scoring-rules/:idDelete rule
GET/lead-settings/qualification-thresholdGet threshold
PUT/lead-settings/qualification-thresholdSet threshold

Team Roles

MethodPathDescription
GET/lead-settings/team-rolesList team roles
POST/lead-settings/team-rolesCreate role

General Settings

MethodPathDescription
GET/lead-settings/settingsGet all lead settings
PUT/lead-settings/settingsUpdate lead settings