v1.0 • Lead Management
Retrieve leads with filtering and pagination
Retrieve leads with powerful filtering and pagination options
GET ${baseUrl}/api/v1/leadsControl pagination, filtering, and search
pagePage number (default: 1)
limitResults per page (max: 100)
statusFilter by lead status
sourceFilter by lead source
searchSearch in name and email
GET /api/v1/leads?page=1&limit=20GET /api/v1/leads?status=new&page=1&limit=10GET /api/v1/leads?search=john&status=contacted&source=website&limit=10Returns paginated list of leads matching your criteria
{
"success": true,
"data": {
"leads": [
{
"id": "lead_1234567890abcdef",
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1-555-123-4567",
"source": "website",
"status": "new",
"metadata": {
"utm_source": "google",
"company": "Tech Corp"
},
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
},
{
"id": "lead_0987654321fedcba",
"name": "Jane Smith",
"email": "jane.smith@example.com",
"phone": "+1-555-987-6543",
"source": "referral",
"status": "contacted",
"metadata": {},
"createdAt": "2024-01-14T15:45:00.000Z",
"updatedAt": "2024-01-14T16:00:00.000Z"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 25,
"totalPages": 3,
"hasNext": true,
"hasPrev": false
}
}
}leadsArray of lead objects
paginationPagination metadata
totalTotal leads matching filters
totalPagesTotal number of pages
hasNextWhether more pages exist
hasPrevWhether previous pages exist
Implementation examples with pagination and filtering
# Basic list request
curl -X GET "https://your-domain.com/api/v1/leads?page=1&limit=10" \
-H "Authorization: Bearer sk-workspace_your_api_key"
# With filters
curl -X GET "https://your-domain.com/api/v1/leads?status=new&search=john&limit=5" \
-H "Authorization: Bearer sk-workspace_your_api_key"const listLeads = async (options = {}) => {
const {
page = 1,
limit = 10,
status,
source,
search
} = options;
// Build query parameters
const params = new URLSearchParams({
page: page.toString(),
limit: limit.toString()
});
if (status) params.append('status', status);
if (source) params.append('source', source);
if (search) params.append('search', search);
try {
const response = await fetch(`https://your-domain.com/api/v1/leads?${params}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer sk-workspace_your_api_key',
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
return result.data;
} catch (error) {
console.error('Error listing leads:', error);
throw error;
}
};
// Usage examples
listLeads(); // Get first 10 leads
listLeads({ status: 'new', limit: 20 }); // Get 20 new leads
listLeads({ search: 'john', page: 2 }); // Search for "john" on page 2import requests
from typing import Dict, List, Optional
def list_leads(api_key: str, **filters) -> Dict:
"""
List leads with optional filtering and pagination.
Args:
api_key: Your API key
page: Page number (default: 1)
limit: Results per page (default: 10, max: 100)
status: Filter by status
source: Filter by source
search: Search in name and email
"""
url = "https://your-domain.com/api/v1/leads"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# Default parameters
params = {
'page': filters.get('page', 1),
'limit': min(filters.get('limit', 10), 100) # Enforce max limit
}
# Add optional filters
for key in ['status', 'source', 'search']:
if key in filters and filters[key]:
params[key] = filters[key]
try:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
result = response.json()
data = result['data']
print(f"Found {data['pagination']['total']} leads "
f"(showing {len(data['leads'])} on page {data['pagination']['page']})")
return data
except requests.exceptions.RequestException as e:
print(f"Error listing leads: {e}")
raise
# Usage examples
api_key = "sk-workspace_your_api_key"
# Basic usage
leads_data = list_leads(api_key)
# With filters
new_leads = list_leads(
api_key,
status='new',
limit=20
)
# Search functionality
search_results = list_leads(
api_key,
search='john',
page=1,
limit=5
)Efficient strategies for handling large datasets
10-50 items per page for UI, up to 100 for bulk operations
Use these fields instead of calculating from totals
Use status + search for better performance
Pages over 100 items may be slow
Store results temporarily to reduce API calls
Use API filters instead of client-side filtering
// Fetch all leads using pagination
const fetchAllLeads = async (apiKey) => {
const allLeads = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await fetch(`https://your-domain.com/api/v1/leads?page=${page}&limit=50`, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
const result = await response.json();
const { leads, pagination } = result.data;
allLeads.push(...leads);
hasMore = pagination.hasNext;
page++;
}
return allLeads;
};