POST /functions/v1/api with resource: "leads".
Access control
Regular users can only access leads from agents they own. Internal admins can access all leads using
adminMode: true and optionally scope to a specific user with userId.Get lead statistics
Retrieves aggregated statistics about leads, including total count and breakdown by status. Aggregation happens at the database level for optimal performance.Must be
"leads"Must be
"stats"Response
Leads with a
null status or a status outside the four standard values are not counted in any by_status category but are included in total.List all leads
Retrieves all leads with full field details and relations.Must be
"leads"Must be
"all"Response
List leads (summary)
Retrieves leads with basic fields only, optimized for table views. Accepts the same parameters asall.
Must be
"leads"Must be
"list"Same parameters as
all (filters, pagination, admin options).Response
Same response structure asall, but each lead contains only summary fields:
Get a lead
Retrieves a specific lead by ID with all fields and relations.Must be
"leads"Must be
"get"The lead ID.
Response
Create a lead
Creates a new lead associated with an agent.Must be
"leads"Must be
"create"Response (status 201)
The
user_id on the created lead is resolved in this order: (1) provided user_id parameter, (2) agent’s owning user, (3) current authenticated user.Update a lead
Updates an existing lead. This is a partial update — only include the fields you want to change.Must be
"leads"Must be
"update"The lead ID.
Any combination of lead fields. All fields except
id and created_at can be updated. See the create action for the full list of fields.Response
Delete a lead
Permanently deletes a lead. This is a hard delete with no recovery.Must be
"leads"Must be
"delete"The lead ID.
Response
Lead object
The full lead object returned byall, get, create, and update actions.
Enum values reference
status
| Value | Description |
|---|---|
"new" | Lead has been captured but not yet contacted |
"contacted" | Initial outreach has been made |
"qualified" | Lead has been vetted and meets criteria |
"converted" | Lead has been successfully converted |
priority
| Value | Description |
|---|---|
"low" | Low urgency |
"medium" | Standard urgency |
"high" | Requires immediate attention |
preferred_contact_method
| Value | Description |
|---|---|
"email" | Contact via email |
"phone" | Contact via phone call |
"sms" | Contact via text message |
Filtering reference
All list-style actions (stats, all, list) accept a filters object with the following fields:
| Filter | Type | Description |
|---|---|---|
agentId | string | Filter by a single agent |
agentIds | string[] | Filter by multiple agents |
status | string | Exact match on lead status (not available on stats) |
priority | string | Exact match on lead priority |
searchTerm | string | Partial match across name, email, and phone |
dateRange | string | One of "7d", "30d", "90d", "all" |
Admin operations
Admin operations require the
internal_admin role. Regular users receive a 403 Forbidden response.View all leads across all users
View a specific user’s leads
Create a lead as another user
Error responses
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | Missing or invalid required parameters |
| 401 | UNAUTHORIZED | Invalid or missing authentication token |
| 403 | FORBIDDEN | User does not have access to the agent |
| 404 | NOT_FOUND | Lead not found |
| 500 | INTERNAL_ERROR | Server error |

