# Spain BORME NIF Portfolio Event Monitor (`plym-actor-factory/spain-borme-nif-portfolio-monitor`) Actor

Watch a list of Spanish NIFs (with company legal names) and emit typed BORME gazette events — appointments, capital, insolvency, dissolution, address/name changes — from official BOE open data. Not a nationwide BORME dump.

- **URL**: https://apify.com/plym-actor-factory/spain-borme-nif-portfolio-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 $20.00 / 1,000 borme 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

## Spain BORME NIF Portfolio Event Monitor

Watch a **book of Spanish NIFs** (with company legal names) and receive **typed BORME gazette events** the day BOE publishes director changes, capital events, insolvency/concurso, dissolution, address/name changes for those companies. **Not** a nationwide BORME dump. **Not** a Registro Mercantil directory scrape. **Not** paid eInforma / BORME API seats.

### Value proposition

- **NIF watchlist × daily official BORME ingest** → `DIRECTOR_APPOINTED`, `DIRECTOR_TERMINATED`, `CAPITAL_INCREASE`, `CAPITAL_REDUCTION`, `INSOLVENCY_DECLARED`, `DISSOLUTION`, `ADDRESS_CHANGED`, `NAME_CHANGED` (optional `INCORPORATION` off by default).
- Official **BOE datos abiertos** BORME sumario + province XML only. Fair-use HTTP pacing. **No paid BORME API / AlertaEmpresas / eInforma key.**
- **Pay only for unique delivered acts on watched NIFs.** Quiet days ≈ $0. Durable KVS checkpoint + `event_uid` dedupe. Events carry boletin/acto provenance + `match_confidence`.

### 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 BOE. That fixture path only writes a non-billable `RUN_STATUS` / `FIXTURE_HEALTH` row. It is **not** BORME monitoring.

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

1. Set **`sourceMode` = `live`**
2. Provide `watchlistPairs` as `NIF|Company legal name` (see matching note below)
3. Schedule runs on business days (or use `lookbackDays` for catch-up) with fair-use `requestPaceMs`
4. Optionally set `provinces` (e.g. `MADRID`) to reduce XML fetches for regional books

Official references:

- [BOE datos abiertos API](https://boe.es/datosabiertos/api/api.php)
- [BORME sumario API docs (PDF)](https://boe.es/datosabiertos/documentos/APIsumarioBORME.pdf)
- Endpoint: `https://boe.es/datosabiertos/api/borme/sumario/{YYYYMMDD}`

### Matching note (read before buying)

Official **BORME Section A XML does not publish NIF**. Matching is by **company denominación** supplied in your watchlist, with `match_confidence` (`exact` / `normalized` / `contains`). Ambiguous short names may miss or false-positive — prefer full registered names. Administrator personal names appear in statutory gazette text (PII as published).

### Data limitations

- Publication days only (no BORME on many weekends/holidays) — 404 days are idle, not errors.
- Large nationwide scans need higher `maxRunSeconds` or a `provinces` filter.
- First-seen acts are delivered when they match; duplicates are deduped via `event_uid`.
- We cite Agencia Estatal BOE as the data origin. This Actor is not affiliated with or endorsed by BOE / Registro Mercantil.

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

| Field | Default |
|-------|---------|
| `watchlistPairs` | demo NIF|name pairs |
| `eventTypes` | director / capital / insolvency / dissolution / address / name (no incorporation) |
| `sourceMode` | `fixture` |
| `emitFixtureDemoEvents` | `false` |
| `maxRunSeconds` | `55` |
| `maxEvents` | `500` |

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

### Input (summary)

| Field | Notes |
|-------|--------|
| `watchlistPairs` | `NIF\|Company legal name` (preferred) |
| `nifNumbers` + `companyNames` | Alternate aligned lists |
| `eventTypes` | Typed filters; `INCORPORATION` opt-in |
| `provinces` | Optional province title filter |
| `publicationDate` / `lookbackDays` | Live scan window |
| `sourceMode` | `fixture` (default) or `live` |
| `emitFixtureDemoEvents` | Default **false** |
| `maxRunSeconds` / `maxEvents` | Budgets |
| `resumeFromCheckpoint` | Default true |
| `requestPaceMs` | Fair-use delay (default 400) |

#### Production example

```json
{
  "watchlistPairs": [
    "A28015865|TELEFONICA SA",
    "B86656961|FREEMATICA ESPAÑA SOCIEDAD LIMITADA"
  ],
  "eventTypes": [
    "DIRECTOR_APPOINTED",
    "DIRECTOR_TERMINATED",
    "CAPITAL_INCREASE",
    "CAPITAL_REDUCTION",
    "INSOLVENCY_DECLARED",
    "DISSOLUTION",
    "ADDRESS_CHANGED",
    "NAME_CHANGED"
  ],
  "sourceMode": "live",
  "provinces": ["MADRID"],
  "lookbackDays": 3,
  "maxRunSeconds": 120,
  "requestPaceMs": 400,
  "resumeFromCheckpoint": true
}
```

### Output

#### Portfolio events (billable under PPE)

Typed rows include: `nif`, `company_name`, `matched_name`, `match_confidence`, `event_type`, `act_id`, `boletin_id`, `province`, `publication_date`, `act_excerpt`, `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: **`borme-event-delivered`** at **$0.02** per delivered unique portfolio act ($20 / 1,000). Single tier (see `docs/monetization.md` and ADR 0010). Health / duplicate / fixture rows are never charged.

### Local development

```bash
cd actors/spain-borme-nif-portfolio-monitor
npm install
npm test
npm run build
npm run start:dev
```

### Legal

BORME is an official public-sector gazette. Reuse under Spanish open-data / reutilisation framing (Ley 18/2015 / RD 1495/2011 — same basis commercial BORME APIs cite). Do **not** use this Actor against paid Registradores certificate portals.

# Actor input Schema

## `watchlistPairs` (type: `array`):

Portfolio entries as "NIF|Company legal name". Official BORME Section A does not publish NIF — matching uses the company denominación with a confidence field. Invalid rows are skipped with no charge.

## `nifNumbers` (type: `array`):

Optional alternate to watchlistPairs — must align index-wise with companyNames.

## `companyNames` (type: `array`):

Optional alternate to watchlistPairs — must align index-wise with nifNumbers.

## `eventTypes` (type: `array`):

Which typed BORME events to emit. Default excludes INCORPORATION (new-lead mode off). Allowed: DIRECTOR\_APPOINTED, DIRECTOR\_TERMINATED, CAPITAL\_INCREASE, CAPITAL\_REDUCTION, INSOLVENCY\_DECLARED, DISSOLUTION, ADDRESS\_CHANGED, NAME\_CHANGED, INCORPORATION.

## `provinces` (type: `array`):

Optional BORME province titles to limit XML fetches (e.g. MADRID, BARCELONA). Empty = all provinces in the day's sumario.

## `publicationDate` (type: `string`):

BORME publication day to scan. Default = today (UTC). Use with lookbackDays for catch-up.

## `lookbackDays` (type: `integer`):

How many calendar days (including publicationDate) to scan on live runs. Weekends/holidays 404 quietly.

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

Wall-clock budget for this scheduled poll.

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

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

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

If true, resume lastPublicationDate 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 BOE BORME sumario + province XML (fair-use; no paid BORME API key).

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

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

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

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

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

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

## Actor input object example

```json
{
  "watchlistPairs": [
    "B86656961|FREEMATICA ESPAÑA SOCIEDAD LIMITADA",
    "B87999888|MARCO RESIDENCIAL SL"
  ],
  "eventTypes": [
    "DIRECTOR_APPOINTED",
    "DIRECTOR_TERMINATED",
    "CAPITAL_INCREASE",
    "CAPITAL_REDUCTION",
    "INSOLVENCY_DECLARED",
    "DISSOLUTION",
    "ADDRESS_CHANGED",
    "NAME_CHANGED"
  ],
  "lookbackDays": 1,
  "maxRunSeconds": 55,
  "maxEvents": 500,
  "resumeFromCheckpoint": true,
  "sourceMode": "fixture",
  "emitFixtureDemoEvents": false,
  "requestPaceMs": 400
}
```

# Actor output Schema

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

JSON summary: delivered, charged, runStatus, checkpoint, stats, as\_of

# 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/spain-borme-nif-portfolio-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/spain-borme-nif-portfolio-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/spain-borme-nif-portfolio-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,plym-actor-factory/spain-borme-nif-portfolio-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/mcvdx8nLIqoD5qRV5/builds/w8gLpsdpyNe5LlWPt/openapi.json
