# US Contractor License Risk Event Monitor (`plym-actor-factory/us-contractor-license-risk-monitor`) Actor

Watch a book of California CSLB contractor license numbers and emit typed risk events (LICENSE\_*/BOND\_*/WORKERS\_COMP\_\*) from official CSLB Public Data Portal bulk files. Scheduled poll — not real-time. Pay only for unique delivered risk events. Multi-state expansion later.

- **URL**: https://apify.com/plym-actor-factory/us-contractor-license-risk-monitor.md
- **Developed by:** [Daniel Witney](https://apify.com/plym-actor-factory) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $25.00 / 1,000 license risk event delivereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

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

## US Contractor License Risk Event Monitor

Watch a **book of California CSLB contractor license numbers** and receive **typed risk events** when official CSLB Public Data Portal bulk files show material changes — suspensions, cancellations / portal absences, expirations, bond lapses, workers’-comp lapses, and reactivations — **not** another statewide contractor directory dump.

**Honest title:** CSLB-first scheduled poll / catch-up monitor. Multi-state registries (AZ ROC, FL DBPR, …) are roadmap only. Detection latency ≈ your schedule interval + CSLB weekly master refresh lag.

### Value proposition

- **Not a directory dump** and **not** a Notion-only expiry checker: dataset emits typed risk events for agents / Clay / Slack / webhooks.

- Unlike check-priced multi-state wrappers that bill per license lookup (and may chain child scrapers), you pay only when a **material risk event** is delivered.

- Typed events: `LICENSE_SUSPENDED`, `LICENSE_REVOKED`, `LICENSE_CANCELLED`, `LICENSE_EXPIRED`, `BOND_LAPSED`, `WORKERS_COMP_LAPSED`, `STATUS_REACTIVATED`

- Official / public HTTP only — CSLB Public Data Portal **License Master** CSV (`DownLoadFile.ashx?fName=MasterLicenseData&type=C`). **No paid Constructity** and **no $235 paid full-file order** for MVP.

- **Pay only for unique delivered risk events.** First observation stores a baseline (no charge). Quiet days ≈ $0.

- Durable KVS checkpoint + `event_uid` dedupe.

### PRODUCTION USE (required for real monitoring)

> **Store default ≠ product.** Schema defaults use `sourceMode=fixture` so Apify Store daily auto-tests leave a non-empty health dataset **without** calling CSLB. That fixture path only writes a non-billable `RUN_STATUS` / `FIXTURE_HEALTH` row. It is **not** license monitoring.

For **production monitoring** you **must**:

1. Set **`sourceMode` = `live`**
2. Provide your `licenseNumbers` watchlist / book (CA CSLB)
3. Keep `states` including `CA` (only supported registry in MVP)
4. Schedule runs (e.g. daily / weekly aligned with CSLB master refresh) with fair-use `requestPaceMs`

Official references:

- [CSLB Public Data Portal — Master List](https://www.cslb.ca.gov/Onlineservices/DataPortal/ContractorList)
- Direct CSV: `https://www.cslb.ca.gov/OnlineServices/DataPortal/DownLoadFile.ashx?fName=MasterLicenseData&type=C`
- [CSLB Instant License Check](https://www.cslb.ca.gov/OnlineServices/CheckLicenseII/CheckLicense.aspx) (manual corroboration)

### Data limitations (read before buying)

- **Not real-time.** CSLB regenerates the free statewide master roughly **weekly**. This Actor is a scheduled poll of that file.
- **Free Public Data Portal master excludes** licences that are cancelled, revoked, or expired **non-renewable**. When a watchlist license **disappears** from the master, we emit `LICENSE_CANCELLED` with subtype `PUBLIC_MASTER_ABSENCE` — honest that the free file does not distinguish cancel vs revoke vs expired-non-renewable. Use Instant Check for exact disposition.
- Suspensions that remain on the renewable master (e.g. `Work Comp Susp`, `Contr Bond Susp`) are observed as status / bond / WC field diffs.
- **First run** stores baselines only — you will not be charged for “current state” snapshots.
- Fair-use pacing applies; the live path downloads the full statewide CSV then filters to your book (CU cost is mostly download + parse).
- We cite California Contractors State License Board as the data origin. This Actor is not affiliated with or endorsed by CSLB.
- Multi-state expansion is **not** implemented yet — non-CA `states` are skipped with a warning.

### Apify Store daily auto-test / default input

| Field | Default |
|-------|---------|
| `licenseNumbers` | `["1000000","999999"]` |
| `states` | `["CA"]` |
| `signalGroups` | `license`, `bond`, `workers_comp` |
| `sourceMode` | `fixture` |
| `emitFixtureDemoEvents` | `false` |
| `maxRunSeconds` | `300` |
| `maxEvents` | `500` |

On that path the Actor **SUCCEEDS** quickly, pushes exactly one `RUN_STATUS` / `FIXTURE_HEALTH` row (`billable: false`), and does **not** charge `license-risk-event-delivered`.

### Input (summary)

| Field | Notes |
|-------|--------|
| `licenseNumbers` | Watchlist (required) |
| `states` | MVP: `CA` only |
| `signalGroups` | `license`, `bond`, `workers_comp` |
| `sourceMode` | `fixture` (default) or `live` |
| `emitFixtureDemoEvents` | Default **false** |
| `maxRunSeconds` / `maxEvents` | Budgets |
| `resumeFromCheckpoint` | Default true |
| `requestPaceMs` | Fair-use delay (default 250) |

#### Production example

```json
{
  "licenseNumbers": ["1000000", "123456", "789012"],
  "states": ["CA"],
  "signalGroups": ["license", "bond", "workers_comp"],
  "sourceMode": "live",
  "maxRunSeconds": 360,
  "requestPaceMs": 250,
  "resumeFromCheckpoint": true
}
```

### Output

#### Risk events (billable under PPE)

Typed rows include: `license_number`, `business_name`, `state`, `event_type`, `event_subtype`, `changed_fields`, `previous_value`, `new_value`, `effective_date`, `evidence`, `summary`, `source_url`, `event_uid`, `billable: true`.

#### RUN\_STATUS (never billed)

Every successful run pushes one health row (`FIXTURE_HEALTH` | `MONITOR_IDLE` | `CATCHUP_COMPLETE` | `HEALTH_OK`).

### Pricing

Pay-per-event: **`license-risk-event-delivered`** at **$0.025** per delivered unique risk event ($25 / 1,000). Single tier (see `docs/monetization.md` and ADR 0010). Health / baseline / duplicate / fixture rows are never charged.

### Local development

```bash
cd actors/us-contractor-license-risk-monitor
npm install
npm test
npm run build
## Store-safe fixture health:
apify run -p
## Demo typed events locally:
## set input emitFixtureDemoEvents=true (still sourceMode=fixture)
```

### Attribution

Data originates from the **California Contractors State License Board (CSLB)** Public Data Portal. Not an official CSLB product.

# Actor input Schema

## `licenseNumbers` (type: `array`):

California CSLB license numbers to monitor (digits only after normalize). Invalid entries are skipped with no charge. Multi-state numbers ignored until state expansion ships.

## `states` (type: `array`):

Registry states to poll. MVP supports CA (CSLB Public Data Portal) only. Other codes are skipped with a warning until expansion.

## `signalGroups` (type: `array`):

Which risk signal groups to evaluate: license, bond, workers\_comp. Default: all.

## `maxRunSeconds` (type: `integer`):

Wall-clock budget for this scheduled poll (includes bulk CSV download).

## `maxEvents` (type: `integer`):

Stop after this many unique risk events are delivered (does not include RUN\_STATUS).

## `resumeFromCheckpoint` (type: `boolean`):

If true, resume license snapshots and seen event\_uids from the default Key-Value Store.

## `sourceMode` (type: `string`):

fixture = local/CI / Apify Store daily auto-test default (no network; emits RUN\_STATUS only unless emitFixtureDemoEvents=true). live = official CSLB Public Data Portal bulk download (License Master CSV).

## `emitFixtureDemoEvents` (type: `boolean`):

When sourceMode=fixture, if true push fabricated risk events from local fixtures (unit/local demos only). Default false so Store daily auto-tests never emit fake risk events or charge license-risk-event-delivered. Production: leave false and use sourceMode=live.

## `maxTotalChargeUsd` (type: `number`):

Optional soft budget hint for delivered risk events. Platform ACTOR\_MAX\_TOTAL\_CHARGE\_USD also applies when set.

## `requestPaceMs` (type: `integer`):

Minimum delay between outbound official HTTP requests (fair-use pacing).

## Actor input object example

```json
{
  "licenseNumbers": [
    "1000000",
    "999999"
  ],
  "states": [
    "CA"
  ],
  "signalGroups": [
    "license",
    "bond",
    "workers_comp"
  ],
  "maxRunSeconds": 300,
  "maxEvents": 500,
  "resumeFromCheckpoint": true,
  "sourceMode": "fixture",
  "emitFixtureDemoEvents": false,
  "requestPaceMs": 250
}
```

# Actor output Schema

## `OUTPUT` (type: `string`):

JSON summary: delivered, charged, runStatus, checkpoint, stats

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("plym-actor-factory/us-contractor-license-risk-monitor").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("plym-actor-factory/us-contractor-license-risk-monitor").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 '{}' |
apify call plym-actor-factory/us-contractor-license-risk-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,plym-actor-factory/us-contractor-license-risk-monitor"
        }
    }
}
```

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/dQObl9A47rIGClcAC/builds/SdSaQ4SKMuhIadjxa/openapi.json
