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

# lead_extractor.job.completed

> Triggered when a Lead Extractor campaign completes

This event is triggered when a Lead Extractor (LinkedIn scraper) campaign finishes extracting and optionally enriching leads.

## When This Event Fires

* A Lead Extractor campaign initiated via the API completes
* All leads have been extracted from the provided LinkedIn search URLs
* Enrichment is complete (if enabled)
* The campaign status changes to `FINISHED`

## Payload

```json theme={null}
{
  "eventId": "evt_1708456789123_abc123def",
  "eventType": "lead_extractor.job.completed",
  "timestamp": "2024-02-24T10:30:00.000Z",
  "workspaceId": "ws_abc123xyz",
  "data": {
    "campaign_id": "camp_abc123",
    "campaign_name": "Tech Startup Founders",
    "campaign_type": "SEARCH",
    "mode": "with_enrichment",
    "search_urls": [
      "https://www.linkedin.com/search/results/people/?keywords=CEO%20startup"
    ],
    "total_leads_extracted": 100,
    "total_leads_enriched": 95,
    "requested_limit": 100,
    "started_at": "2024-02-24T10:00:00.000Z",
    "completed_at": "2024-02-24T10:30:00.000Z",
    "duration_ms": 1800000,
    "credits_used": {
      "extraction": 100,
      "enrichment": 100,
      "total": 200
    },
    "leads": [
      {
        "id": "lead_xyz789",
        "linkedin_identifier": "johndoe",
        "linkedin_url": "https://www.linkedin.com/in/johndoe",
        "first_name": "John",
        "last_name": "Doe",
        "full_name": "John Doe",
        "headline": "CEO at TechCorp | Building the future of AI",
        "summary": "Experienced technology executive with 15+ years...",
        "location": "San Francisco Bay Area",
        "city": "San Francisco",
        "country": "United States",
        "profile_picture_url": "https://media.licdn.com/...",
        "company": "TechCorp Inc",
        "job_position": "CEO",
        "email": "john.doe@techcorp.com",
        "phone": "+1-555-123-4567",
        "connections": 500,
        "followers": 12500,
        "experience": [
          {
            "title": "CEO",
            "company": "TechCorp Inc",
            "duration": "2020 - Present"
          }
        ],
        "education": [
          {
            "school": "Stanford University",
            "degree": "MBA"
          }
        ],
        "skills": ["Leadership", "Strategy", "AI/ML"]
      }
    ],
    "results_url": "/v1/lead-extractor/campaigns/camp_abc123/results"
  }
}
```

## Payload Fields

| Field                        | Type   | Description                                             |
| ---------------------------- | ------ | ------------------------------------------------------- |
| `eventId`                    | string | Unique event identifier for idempotency                 |
| `eventType`                  | string | Always `lead_extractor.job.completed`                   |
| `timestamp`                  | string | ISO 8601 timestamp when the job completed               |
| `workspaceId`                | string | Your workspace ID                                       |
| `data.campaign_id`           | string | Unique identifier for the campaign                      |
| `data.campaign_name`         | string | Name you provided for the campaign                      |
| `data.campaign_type`         | string | Type: `SEARCH`, `SALES_NAVIGATOR`, or `POST_ENGAGEMENT` |
| `data.mode`                  | string | `extraction_only` or `with_enrichment`                  |
| `data.search_urls`           | array  | LinkedIn search URLs that were scraped                  |
| `data.total_leads_extracted` | number | Total leads extracted                                   |
| `data.total_leads_enriched`  | number | Leads with enrichment data (0 if extraction\_only)      |
| `data.requested_limit`       | number | Maximum leads you requested                             |
| `data.started_at`            | string | When the campaign started                               |
| `data.completed_at`          | string | When the campaign completed                             |
| `data.duration_ms`           | number | Processing time in milliseconds                         |
| `data.credits_used`          | object | Credits consumed breakdown                              |
| `data.leads`                 | array  | Array of all extracted leads with full data             |
| `data.results_url`           | string | API endpoint to fetch results                           |

### Lead Object Fields

Each lead in the `leads` array contains extensive profile data:

| Field                 | Type   | Description               |
| --------------------- | ------ | ------------------------- |
| `id`                  | string | Unique lead identifier    |
| `linkedin_identifier` | string | LinkedIn username         |
| `linkedin_url`        | string | Full LinkedIn profile URL |
| `first_name`          | string | First name                |
| `last_name`           | string | Last name                 |
| `full_name`           | string | Full name                 |
| `headline`            | string | LinkedIn headline         |
| `summary`             | string | Profile summary/about     |
| `location`            | string | Location string           |
| `city`                | string | City                      |
| `country`             | string | Country                   |
| `profile_picture_url` | string | Profile photo URL         |
| `company`             | string | Current company           |
| `job_position`        | string | Current job title         |
| `email`               | string | Email (if enriched)       |
| `phone`               | string | Phone (if enriched)       |
| `connections`         | number | Connection count          |
| `followers`           | number | Follower count            |
| `experience`          | array  | Work experience history   |
| `education`           | array  | Education history         |
| `skills`              | array  | Listed skills             |

## Use Cases

<CardGroup cols={2}>
  <Card title="CRM Import" icon="database">
    Automatically import enriched leads into your CRM
  </Card>

  <Card title="Outreach Campaigns" icon="rocket">
    Trigger LinkedIn outreach campaigns with extracted leads
  </Card>

  <Card title="Lead Scoring" icon="star">
    Score and prioritize leads based on profile data
  </Card>

  <Card title="Data Sync" icon="arrows-rotate">
    Keep your lead database in sync with LinkedIn
  </Card>
</CardGroup>

## Example Handler

```javascript theme={null}
app.post('/webhooks/sendpilot', (req, res) => {
  const event = req.body;
  
  if (event.eventType === 'lead_extractor.job.completed') {
    const { 
      campaign_id, 
      campaign_name, 
      total_leads_extracted,
      credits_used,
      leads 
    } = event.data;
    
    // Import leads to CRM with enriched data
    for (const lead of leads) {
      await crm.createOrUpdateLead({
        firstName: lead.first_name,
        lastName: lead.last_name,
        email: lead.email,
        phone: lead.phone,
        company: lead.company,
        title: lead.job_position,
        linkedinUrl: lead.linkedin_url,
        headline: lead.headline,
        location: lead.location,
        source: `SendPilot Extractor: ${campaign_name}`
      });
    }
    
    // Send notification with credits summary
    await slack.notify({
      channel: '#lead-generation',
      text: `✅ Lead Extractor "${campaign_name}" completed!\n` +
            `Extracted: ${total_leads_extracted} leads\n` +
            `Credits used: ${credits_used.total}`
    });
    
    console.log(`Campaign ${campaign_id} completed with ${total_leads_extracted} leads`);
  }
  
  res.status(200).send('OK');
});
```

<Note>
  The `leads` array contains all extracted leads with complete profile data. For campaigns with enrichment enabled, email and phone fields will be populated when available.
</Note>
