Dashboard

Update Lead

Modify an existing lead's information

PUT
4 min read

Endpoint Details

Update specific fields of an existing lead

HTTP Method & URL

PUT ${baseUrl}/api/v1/leads/{leadId}

Path Parameters

leadId

The unique identifier of the lead to update (required)

string

Partial Updates

Only include fields you want to change

💡 Smart Merging

You only need to include the fields you want to update. Existing fields will remain unchanged.

  • Metadata merging: New metadata fields are added, existing ones are updated
  • Array handling: Arrays in metadata are replaced, not merged
  • Null values: Send null to clear a field

Example Update Requests

Update status and phone

{
  "status": "contacted",
  "phone": "+1-555-123-9999"
}

Add metadata and notes

{
  "metadata": {
    "last_interaction": "2024-01-16T14:30:00.000Z",
    "notes": "Interested in premium package",
    "follow_up_date": "2024-01-20",
    "lead_score": 85
  }
}

Complete field update

{
  "name": "John Smith",
  "phone": "+1-555-456-7890",
  "status": "qualified",
  "source": "webinar",
  "metadata": {
    "company": "New Tech Corp",
    "job_title": "Senior Manager", 
    "budget": "$50k-100k",
    "timeline": "Q2 2024",
    "interests": ["enterprise_solution", "support_package"]
  }
}

Response

Returns the updated lead with new timestamps

Success Response (200 OK)

{
  "success": true,
  "data": {
    "id": "lead_1234567890abcdef",
    "name": "John Smith",
    "email": "john.doe@example.com",
    "phone": "+1-555-456-7890",
    "source": "webinar",
    "status": "qualified",
    "metadata": {
      "utm_source": "google",
      "utm_campaign": "spring_2024",
      "company": "New Tech Corp",
      "job_title": "Senior Manager",
      "budget": "$50k-100k",
      "timeline": "Q2 2024",
      "interests": ["enterprise_solution", "support_package"]
    },
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-16T14:30:00.000Z",
    "workspaceId": "ws_your_workspace_id"
  }
}

Key Changes

updatedAt

Timestamp reflects the update time

metadata

Merged with existing data

Unchanged Fields

id

Always remains the same

createdAt

Never changes after creation

workspaceId

Cannot be modified

Code Examples

Implementation examples for updating leads

cURL

curl -X PUT "https://your-domain.com/api/v1/leads/lead_1234567890abcdef" \
  -H "Authorization: Bearer sk-workspace_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "contacted",
    "metadata": {
      "notes": "Follow up scheduled for next week",
      "last_interaction": "2024-01-16T14:30:00.000Z"
    }
  }'

JavaScript (fetch)

const updateLead = async (leadId, updates) => {
  try {
    const response = await fetch(`https://your-domain.com/api/v1/leads/${leadId}`, {
      method: 'PUT',
      headers: {
        'Authorization': 'Bearer sk-workspace_your_api_key',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(updates)
    });

    if (!response.ok) {
      if (response.status === 404) {
        throw new Error('Lead not found');
      }
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const result = await response.json();
    return result.data;
  } catch (error) {
    console.error('Error updating lead:', error);
    throw error;
  }
};

// Usage examples
const leadId = "lead_1234567890abcdef";

// Simple status update
updateLead(leadId, {
  status: "contacted"
});

// Add notes and metadata
updateLead(leadId, {
  metadata: {
    notes: "Very interested in our services",
    lead_score: 90,
    follow_up_date: "2024-01-25"
  }
});

// Multiple field update
updateLead(leadId, {
  phone: "+1-555-999-8888",
  status: "qualified",
  source: "referral",
  metadata: {
    referrer: "Jane Smith",
    budget_range: "$10k-25k"
  }
});

Python (requests)

import requests
from typing import Dict, Any

def update_lead(api_key: str, lead_id: str, updates: Dict[str, Any]) -> Dict[str, Any]:
    """
    Update a lead with partial data.
    
    Args:
        api_key: Your API key
        lead_id: The lead's unique identifier
        updates: Dictionary of fields to update
        
    Returns:
        dict: The updated lead data
    """
    url = f"https://your-domain.com/api/v1/leads/{lead_id}"
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    
    try:
        response = requests.put(url, headers=headers, json=updates)
        
        if response.status_code == 404:
            raise ValueError(f"Lead with ID '{lead_id}' not found")
            
        response.raise_for_status()
        
        result = response.json()
        print(f"Updated lead: {result['data']['name']} - Status: {result['data']['status']}")
        
        return result['data']
    except requests.exceptions.RequestException as e:
        print(f"Error updating lead: {e}")
        raise

# Usage examples
api_key = "sk-workspace_your_api_key"
lead_id = "lead_1234567890abcdef"

# Simple status update
try:
    updated_lead = update_lead(api_key, lead_id, {
        "status": "contacted"
    })
    print(f"Status updated to: {updated_lead['status']}")
except Exception as e:
    print(f"Update failed: {e}")

# Add metadata
update_lead(api_key, lead_id, {
    "metadata": {
        "notes": "Interested in enterprise solution",
        "follow_up_date": "2024-01-25",
        "priority": "high"
    }
})

# Helper function for common updates
def update_lead_status(api_key: str, lead_id: str, status: str, notes: str = None):
    """Update lead status with optional notes."""
    updates = {"status": status}
    if notes:
        updates["metadata"] = {"notes": notes}
    
    return update_lead(api_key, lead_id, updates)

# Usage
update_lead_status(api_key, lead_id, "qualified", "Ready for sales team")

Error Scenarios

Handle validation and update errors

400 Bad Request - Validation Error

{
  "success": false,
  "error": "Validation failed",
  "code": "VALIDATION_ERROR",
  "details": {
    "field": "status",
    "value": "invalid_status",
    "message": "Status must be one of: new, contacted, qualified, converted, lost, follow_up"
  }
}

409 Conflict - Email Already Exists

{
  "success": false,
  "error": "Email already exists",
  "code": "DUPLICATE_EMAIL",
  "details": {
    "email": "existing@example.com",
    "existingLeadId": "lead_another123",
    "message": "A different lead with this email already exists in your workspace"
  }
}

✓ Update Best Practices

Only send fields that changed
Validate data before sending
Handle 404 errors for deleted leads
Check for email conflicts

💡 Metadata Tips

Metadata is merged, not replaced
Use null to remove metadata fields
Arrays are replaced completely
Store timestamps for tracking
    PollyBot.ai - Smart Conversations, Seamless Automation