> ## Documentation Index
> Fetch the complete documentation index at: https://api.smartlead.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Export Campaign Leads

> Export all leads from a campaign as a CSV file with complete engagement metrics

<Note>
  Returns a CSV file containing all leads in the campaign with their contact information, status, category, and engagement metrics (opens, clicks, replies). The file is named `sl_campaign_{campaign_id}_leads.csv`.
</Note>

## Path Parameters

<ParamField path="campaign_id" type="number" required>
  The campaign ID to export leads from
</ParamField>

## Query Parameters

<ParamField query="api_key" type="string" required>
  Your SmartLead API key
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  # Download CSV file
  curl "https://server.smartlead.ai/api/v1/campaigns/123/leads-export?api_key=YOUR_KEY" \
    -o campaign_123_leads.csv
  ```

  ```python Python theme={null}
  import requests

  API_KEY = "YOUR_API_KEY"
  campaign_id = 123

  response = requests.get(
      f"https://server.smartlead.ai/api/v1/campaigns/{campaign_id}/leads-export",
      params={"api_key": API_KEY}
  )

  # Save CSV file
  if response.status_code == 200:
      with open(f'campaign_{campaign_id}_leads.csv', 'wb') as f:
          f.write(response.content)
      print(f"Exported {campaign_id} leads to CSV")
  else:
      print(f"Error: {response.status_code}")
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = 'YOUR_API_KEY';
  const campaignId = 123;

  const response = await fetch(
    `https://server.smartlead.ai/api/v1/campaigns/${campaignId}/leads-export?api_key=${API_KEY}`
  );

  if (response.ok) {
    const blob = await response.blob();
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = `campaign_${campaignId}_leads.csv`;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    console.log('CSV downloaded');
  } else {
    console.error('Export failed:', response.status);
  }
  ```
</RequestExample>

## CSV File Columns

The exported CSV file contains the following columns:

<AccordionGroup>
  <Accordion title="Lead Information">
    * `id` - Lead ID
    * `campaign_lead_map_id` - Campaign-lead mapping ID
    * `first_name` - Lead's first name
    * `last_name` - Lead's last name
    * `email` - Lead's email address
    * `phone_number` - Lead's phone number
    * `company_name` - Company name
    * `website` - Company website
    * `location` - Lead's location
    * `linkedin_profile` - LinkedIn profile URL
    * `company_url` - Company URL
    * `custom_fields` - Custom fields as JSON object
  </Accordion>

  <Accordion title="Status & Category">
    * `status` - Lead status (STARTED, INPROGRESS, COMPLETED, PAUSED, STOPPED)
    * `category` - Category name
    * `is_interested` - Boolean indicating positive sentiment category
    * `created_at` - When lead was added to campaign
  </Accordion>

  <Accordion title="Engagement Metrics">
    * `last_email_sequence_sent` - Last sequence number sent
    * `open_count` - Total number of opens
    * `click_count` - Total number of clicks
    * `reply_count` - Total number of replies
  </Accordion>

  <Accordion title="Unsubscribe Status">
    * `is_unsubscribed` - Whether lead is globally unsubscribed
    * `unsubscribed_client_id_map` - Client-specific unsubscribe data
  </Accordion>
</AccordionGroup>

## Response Codes

<ResponseField name="200" type="Success">
  CSV file generated and returned successfully
</ResponseField>

<ResponseField name="401" type="Unauthorized">
  Invalid or missing API key
</ResponseField>

<ResponseField name="404" type="Not Found">
  Campaign not found or you don't have access to it
</ResponseField>

<ResponseField name="500" type="Internal Server Error">
  Server error occurred
</ResponseField>

<ResponseExample>
  ```csv 200 - Success (CSV Content) theme={null}
  id,campaign_lead_map_id,status,category,is_interested,created_at,first_name,last_name,email,phone_number,company_name,website,location,custom_fields,linkedin_profile,company_url,is_unsubscribed,unsubscribed_client_id_map,last_email_sequence_sent,open_count,click_count,reply_count
  2995276770,2433664091,INPROGRESS,Interested,true,2025-11-25T12:54:54.000Z,John,Doe,john@example.com,+1234567890,Acme Corp,https://acme.com,San Francisco,"{""job_title"":""CEO""}",https://linkedin.com/in/johndoe,https://acme.com,false,,2,3,1,1
  ```

  ```json 401 - Unauthorized theme={null}
  {
    "message": "Invalid API Key"
  }
  ```

  ```json 404 - Not Found theme={null}
  {
    "error": "Campaign not found - Invalid campaign_id."
  }
  ```
</ResponseExample>

## Response Headers

<Info>
  The response includes the following headers:

  * `Content-Type: text/csv`
  * `Content-Disposition: attachment; filename=sl_campaign_{campaign_id}_leads.csv`
</Info>

## Usage Notes

<Tip>
  This endpoint is ideal for:

  * Backing up campaign leads
  * Importing leads into CRM systems
  * Analyzing engagement metrics in spreadsheet tools
  * Generating reports for stakeholders
</Tip>

<Warning>
  Large campaigns may take longer to export. The export includes all leads regardless of status.
</Warning>

## Related Endpoints

* [Get Campaign Leads](/api-reference/leads/get-by-campaign) - Paginated API access to leads
* [Get Lead by Email](/api-reference/leads/get-by-email) - Get individual lead details
* [Get All Leads Activities](/api-reference/leads/activities) - Activity timeline for all leads
