Skip to Content
Uncodie Market Fit está disponible 🎉
Rest APIAgentsCmoAssign Leads

Assign Leads

Assigns unassigned leads to team members based on segment performance and availability. This endpoint processes leads that haven’t been assigned to anyone and don’t have any interactions or tasks.

Endpoint

POST /api/agents/cmo/assignLeads

Request Body

ParameterTypeRequiredDescription
site_idstringYesUUID of the site for lead assignment
user_idstringNoUUID of the requesting user (optional)
max_leads_per_segmentnumberNoMaximum leads per segment to process (default: 5, min: 1, max: 10)
prioritystringNoPriority level: ‘low’, ‘normal’, ‘high’, ‘urgent’ (default: ‘normal’)
include_attribution_contextbooleanNoInclude attribution data in results (default: true)

Example Request

{ "site_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "user_id": "12345678-90ab-cdef-1234-567890abcdef", "max_leads_per_segment": 5, "priority": "high", "include_attribution_context": true }

Response Structure

Success Response (200 OK)

{ "success": true, "data": { "assignments": [ { "lead_id": "lead_123", "assignee_id": "user_789", "brief": "**Lead Assignment: John Smith**\n\nCompany: TechCorp...", "intro_message": "Hi John,\n\nI hope this message finds you well...", "segment_info": { "segment_id": "segment_456", "segment_name": "Enterprise SaaS", "attribution_data": { "conversions": 0 } }, "lead_info": { "name": "John Smith", "email": "john@techcorp.com", "company": { "name": "TechCorp", "industry": "Technology" }, "phone": "+1234567890", "origin": "website", "created_at": "2023-12-01T10:00:00Z" } } ], "total_leads_processed": 10, "total_assignments_made": 8, "segments_processed": 3, "summary": { "leads_by_segment": [ { "segment_id": "segment_456", "segment_name": "Enterprise SaaS", "leads_assigned": 3, "assignees": ["user_789", "user_101"] } ], "attribution_strategy": "performance_based", "priority_level": "high" } } }

No Leads Found (200 OK)

{ "success": true, "data": { "assignments": [], "total_leads_processed": 0, "total_assignments_made": 0, "segments_processed": 0, "message": "No leads found without interactions or tasks" } }

Error Response (400 Bad Request)

{ "success": false, "error": { "code": "VALIDATION_ERROR", "message": "Invalid request data", "details": [ { "code": "invalid_string", "expected": "string", "received": "undefined", "path": ["site_id"], "message": "Required" } ] } }

No Team Members Error (400 Bad Request)

{ "success": false, "error": { "code": "NO_TEAM_MEMBERS_AVAILABLE", "message": "No team members available for lead assignment" } }

Internal Server Error (500)

{ "success": false, "error": { "code": "INTERNAL_SERVER_ERROR", "message": "An error occurred while processing lead assignments" } }

Business Logic

Lead Selection Criteria

The system selects leads that meet ALL of the following criteria:

  • Not assigned to any team member (assignee_id is null)
  • Have no conversations
  • Have no tasks
  • Status is not ‘converted’
  • Are associated with a valid segment

Assignment Strategy

  1. Performance-based Assignment: Team members are assigned based on their historical performance with specific segments (conversion rates)
  2. Fallback Assignment: If no performance data is available, uses availability-based assignment
  3. Segment Distribution: Limits the number of leads per segment to prevent overwhelming team members

Generated Content

For each assignment, the system generates:

  • Brief: Comprehensive lead information including company details, segment context, and recommended actions
  • Intro Message: Personalized introduction template for the first contact

Use Cases

Marketing Team Lead Distribution

{ "site_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "max_leads_per_segment": 3, "priority": "normal" }

High Priority Campaign Assignment

{ "site_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "max_leads_per_segment": 10, "priority": "urgent", "include_attribution_context": true }

Specific User Assignment Check

{ "site_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "user_id": "12345678-90ab-cdef-1234-567890abcdef", "max_leads_per_segment": 5 }

Error Codes

CodeDescription
VALIDATION_ERRORInvalid request data format or missing required fields
NO_TEAM_MEMBERS_AVAILABLENo team members found for the site
INTERNAL_SERVER_ERRORServer-side error during processing

Notes

  • The system processes leads in batches to avoid overwhelming team members
  • Performance data is calculated based on historical conversion rates
  • Segments without performance data use round-robin assignment
  • The API is designed to be idempotent - running it multiple times won’t create duplicate assignments
  • All times are in ISO 8601 format
  • UUIDs must be valid v4 format
Last updated on