Dashboard

List Leads

Retrieve leads with filtering and pagination

GET
5 min read

Endpoint Details

Retrieve leads with powerful filtering and pagination options

HTTP Method & URL

GET ${baseUrl}/api/v1/leads

Query Parameters

Control pagination, filtering, and search

Pagination

page

Page number (default: 1)

integer
limit

Results per page (max: 100)

integer

Filtering

status

Filter by lead status

string
source

Filter by lead source

string
search

Search in name and email

string

Example Requests

Basic pagination

GET /api/v1/leads?page=1&limit=20

Filter by status

GET /api/v1/leads?status=new&page=1&limit=10

Search with filters

GET /api/v1/leads?search=john&status=contacted&source=website&limit=10

Response

Returns paginated list of leads matching your criteria

Success Response (200 OK)

{
  "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
    }
  }
}

Response Structure

leads

Array of lead objects

pagination

Pagination metadata

Pagination Fields

total

Total leads matching filters

totalPages

Total number of pages

hasNext

Whether more pages exist

hasPrev

Whether previous pages exist

Code Examples

Implementation examples with pagination and filtering

cURL

# 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"

JavaScript (fetch)

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 2

Python (requests)

import 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
)

Pagination Best Practices

Efficient strategies for handling large datasets

✓ Best Practices

Use reasonable page sizes:

10-50 items per page for UI, up to 100 for bulk operations

Check hasNext/hasPrev:

Use these fields instead of calculating from totals

Combine filters:

Use status + search for better performance

⚠️ Performance Tips

Avoid large pages:

Pages over 100 items may be slow

Cache when possible:

Store results temporarily to reduce API calls

Filter server-side:

Use API filters instead of client-side filtering

Pagination Loop Example

// 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;
};
    PollyBot.ai - Smart Conversations, Seamless Automation