# ReachOwl Lead Finder (`superior_couch/reachowl-lead-finder`) Actor

Find and qualify leads from public website URLs, then optionally import them into an existing ReachOwl campaign via the ReachOwl V1 API.

- **URL**: https://apify.com/superior_couch/reachowl-lead-finder.md
- **Developed by:** [Product Botsify](https://apify.com/superior_couch) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## ReachOwl Lead Finder (Apify Actor)

Production Apify Actor that finds leads from **public website URLs**, qualifies and deduplicates them, and optionally imports them into an **existing** ReachOwl campaign using the same V1 API contract as the ReachOwl MCP (`POST /api/v1/campaigns/{id}/contacts`).

### Architecture

```
APIFY ACTOR (this project)
    ↓
Find + extract + qualify + deduplicate leads
    ↓
ReachOwl V1 API  (same as MCP — not a new API layer)
    ↓
Existing campaign / audience rows

AI AGENT (separate)
    ↓
ReachOwl Skill + ReachOwl MCP
    ↓
Campaign management / Cold DM / Follow-ups / Scheduling
```

This Actor does **not** create campaigns, start outreach, or implement Cold DM / follow-ups.

See [docs/FINDINGS.md](docs/FINDINGS.md) for inspected API contracts and [docs/AGENT_WORKFLOW.md](docs/AGENT_WORKFLOW.md) for how an AI agent should use this Actor with MCP.

### Input

| Field | Type | Default | Notes |
|-------|------|---------|-------|
| `startUrls` | `{url}[]` | required | Public pages to crawl |
| `targetAudience` | string | — | Scoring signal |
| `location` | string | — | Scoring signal |
| `keywords` | string\[] | `[]` | Scoring + link relevance |
| `maxLeads` | int | `100` | Cap after qualify+dedupe |
| `minLeadScore` | int | `50` | Discard below this |
| `maxPagesPerSite` | int | `25` | Per-domain crawl budget |
| `maxRequestsPerCrawl` | int | `200` | Global request cap |
| `sendToReachOwl` | bool | `false` | Import only when true |
| `reachOwlCampaignId` | string | — | **Required** if sending |
| `reachOwlAudienceId` | string | — | Optional; not used as import target (see findings) |
| `scoreWeights` | object | — | Advanced scoring overrides |

#### Example input

```json
{
  "startUrls": [
    { "url": "https://example.com/agents" }
  ],
  "targetAudience": "real estate agents",
  "location": "Lahore, Pakistan",
  "keywords": ["real estate", "property dealer", "real estate agent"],
  "maxLeads": 50,
  "sendToReachOwl": true,
  "reachOwlCampaignId": "CAMPAIGN_ID",
  "reachOwlAudienceId": "AUDIENCE_ID"
}
```

### Output (Dataset)

Each qualified lead is pushed to the Apify Dataset:

```json
{
  "firstName": "Sara",
  "lastName": "Ahmed",
  "fullName": "Sara Ahmed",
  "title": "Real Estate Agent",
  "company": "Agency PK",
  "email": "sara@agency.pk",
  "phone": "923001112233",
  "website": "https://agency.pk",
  "linkedinUrl": null,
  "facebookUrl": null,
  "instagramUrl": null,
  "sourceUrl": "https://agency.pk/team",
  "sourceDomain": "agency.pk",
  "matchedKeywords": ["real estate", "real estate agent"],
  "leadScore": 85,
  "reachOwl": {
    "imported": true,
    "leadId": "99",
    "campaignId": "18312",
    "audienceId": "99"
  }
}
```

Run statistics are stored in the Key-Value store under `STATS` / `OUTPUT`:

- `websitesProcessed`, `pagesVisited`, `leadsDiscovered`, `leadsQualified`, `leadsRejected`, `duplicatesRemoved`, `leadsSentToReachOwl`, `reachOwlImportFailures`

### Environment variables / secrets

Never hardcode credentials. On Apify, set these as Actor secrets:

| Variable | Required | Description |
|----------|----------|-------------|
| `REACHOWL_API_URL` | for import | Base URL, e.g. `https://app.reachowl.com` |
| `REACHOWL_API_KEY` | for import | Sanctum token `id\|plainTextToken` (Bearer) |

Aliases: `REACHOWL_BASE_URL`, `REACHOWL_TOKEN` (same as MCP).

Auth header: `Authorization: Bearer <token>` — identical to ReachOwl MCP.

### ReachOwl integration

When `sendToReachOwl: true`:

1. Validates credentials via `GET /api/v1/user`
2. Verifies campaign via `GET /api/v1/campaigns/{id}`
3. Prefetches contacts via `GET /api/v1/contacts?campaign_id=`
4. Imports each mappable lead via `POST /api/v1/campaigns/{id}/contacts` with `{ audience: [...] }` — **same endpoint as MCP `add_campaign_contacts`**
5. Never claims import success unless the API reports `created > 0` or returns an audience id
6. On ReachOwl outage: scraped leads remain in the Apify Dataset; failures are recorded per lead

**Platform mapping**

- WhatsApp campaigns: require phone → `member_id` `{digits}@c.us` + `https://wa.me/{digits}`
- Facebook / Instagram: require a public profile/website URL; synthetic `member_id` when native IDs are unavailable

### Local development

```bash
cd apify-reachowl-lead-finder
cp .env.example .env   # fill secrets only if testing import
npm install
npm test
npm run build

## Run locally (uses Apify SDK storage under ./storage)
export REACHOWL_API_URL=https://app.reachowl.com
export REACHOWL_API_KEY='id|token'   # optional unless sendToReachOwl
npm run start:dev
```

Provide input via Apify local storage:

```bash
mkdir -p storage/key_value_stores/default
cat > storage/key_value_stores/default/INPUT.json <<'EOF'
{
  "startUrls": [{ "url": "https://example.com" }],
  "targetAudience": "real estate agents",
  "location": "Lahore, Pakistan",
  "keywords": ["real estate"],
  "maxLeads": 10,
  "sendToReachOwl": false
}
EOF
npm run start:dev
```

### Tests

```bash
npm test
```

Coverage includes normalize, score, dedupe, extract, map-to-audience, and ReachOwl import (mocked): auth failure, API failure, success, duplicates, partial failures.

### Apify deployment

```bash
## Install Apify CLI if needed: npm i -g apify-cli
cd apify-reachowl-lead-finder
apify login
apify push
```

Or build the Docker image used on the platform:

```bash
docker build -f .actor/Dockerfile -t reachowl-lead-finder .
```

Set `REACHOWL_API_URL` and `REACHOWL_API_KEY` in the Actor’s Environment variables / secrets on Apify.

### Compliance

- Only public pages; no CAPTCHA/paywall/auth bypass
- Reasonable crawl budgets (`maxPagesPerSite`, `maxRequestsPerCrawl`)
- No fabrication of contact fields
- Secrets never logged

### Project layout

```
apify-reachowl-lead-finder/
  .actor/           # actor.json, input/dataset schemas, Dockerfile
  src/
    main.ts
    crawl/          # crawler + HTML extractors
    qualify/        # lead scoring
    dedupe/         # identity dedupe
    reachowl/       # thin V1 client + import (MCP-compatible)
    utils/
  tests/
  docs/
```

# Actor input Schema

## `startUrls` (type: `array`):

Public website URLs to crawl for leads.

## `targetAudience` (type: `string`):

Who you are looking for (used for qualification scoring).

## `location` (type: `string`):

Optional geographic filter for scoring (e.g. city, country).

## `keywords` (type: `array`):

Keywords that boost relevance when found near a lead.

## `maxLeads` (type: `integer`):

Stop after this many qualified, deduplicated leads.

## `minLeadScore` (type: `integer`):

Discard leads scoring below this threshold (0–100). Default 50.

## `maxPagesPerSite` (type: `integer`):

Crawl budget per start URL domain.

## `maxRequestsPerCrawl` (type: `integer`):

Hard cap on total HTTP requests for the run.

## `sendToReachOwl` (type: `boolean`):

If true, import qualified leads into an existing ReachOwl campaign. Default false.

## `reachOwlCampaignId` (type: `string`):

Existing campaign UUID. Required when sendToReachOwl is true. Actor never creates campaigns.

## `reachOwlAudienceId` (type: `string`):

Reserved for forward compatibility. Current ReachOwl product imports leads as audience rows under the campaign; this ID is not required for import.

## `scoreWeights` (type: `object`):

Optional overrides for qualification scoring weights.

## Actor input object example

```json
{
  "startUrls": [
    {
      "url": "https://example.com/agents"
    }
  ],
  "targetAudience": "real estate agents",
  "location": "Lahore, Pakistan",
  "keywords": [
    "real estate",
    "property dealer",
    "real estate agent"
  ],
  "maxLeads": 100,
  "minLeadScore": 50,
  "maxPagesPerSite": 25,
  "maxRequestsPerCrawl": 200,
  "sendToReachOwl": false
}
```

# Actor output Schema

## `leads` (type: `string`):

Qualified leads (name, title, company, email, phone, score, ReachOwl import status).

## `leadsAllFields` (type: `string`):

Every field of each lead, including social profiles, matched keywords and source URL.

## `stats` (type: `string`):

Pages visited, leads discovered/qualified/rejected, duplicates removed, ReachOwl imports and failures.

## `summary` (type: `string`):

Lead count, statistics and the target ReachOwl campaign for this run.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrls": [
        {
            "url": "https://example.com/agents"
        }
    ],
    "targetAudience": "real estate agents",
    "location": "Lahore, Pakistan",
    "keywords": [
        "real estate",
        "property dealer",
        "real estate agent"
    ],
    "maxLeads": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("superior_couch/reachowl-lead-finder").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "startUrls": [{ "url": "https://example.com/agents" }],
    "targetAudience": "real estate agents",
    "location": "Lahore, Pakistan",
    "keywords": [
        "real estate",
        "property dealer",
        "real estate agent",
    ],
    "maxLeads": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("superior_couch/reachowl-lead-finder").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrls": [
    {
      "url": "https://example.com/agents"
    }
  ],
  "targetAudience": "real estate agents",
  "location": "Lahore, Pakistan",
  "keywords": [
    "real estate",
    "property dealer",
    "real estate agent"
  ],
  "maxLeads": 100
}' |
apify call superior_couch/reachowl-lead-finder --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,superior_couch/reachowl-lead-finder"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/QiQyxQ8bVbmCGEYyE/builds/TrIBcS1zvyfjOShbL/openapi.json
