# Sitemap Status Change Watch (`practical_ai_lab_jp/pal-website-sitemap-status-change-watch`) Actor

Monitors a public HTTPS site's robots-permitted sitemap URLs and reports newly broken, recovered and redirected pages versus a saved per-domain baseline.

- **URL**: https://apify.com/practical_ai_lab_jp/pal-website-sitemap-status-change-watch.md
- **Developed by:** [Practical AI Lab](https://apify.com/practical_ai_lab_jp) (community)
- **Categories:** E-commerce, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 86.7% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 change reports

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Sitemap Status Change Watch

Tells you when pages listed in a public website's sitemap **newly break, recover or start redirecting** between two scheduled runs.

The first run saves a per-domain baseline (`BASELINE_CREATED`). Every later run for the same domain compares a stable sample of sitemap URLs against that baseline and reports only what changed. It is a lightweight monitor for site owners, SEO and web operations teams, and agencies that want a change alert, not a full crawl.

### What it does

1. Reads `robots.txt` first and obeys it (wildcards, `$`, longest-match rules, `Crawl-delay`). If robots rules cannot be read, or they disallow the site, the run stops.
2. Reads the sitemaps listed in `robots.txt` (same origin only), or `/sitemap.xml` if none are listed. Sitemap indexes and `.gz` sitemaps are supported within strict limits.
3. Picks a deterministic hash-based sample of the sitemap URLs, so the same URLs are re-checked on every run.
4. Checks each sampled URL with a `HEAD` request (`GET` without reading the body if `HEAD` is unsupported). Redirects are recorded, never followed. Page bodies are never downloaded.
5. Compares the results with the saved baseline, writes the changes to the dataset and a CSV file, and updates the baseline.

### Input

Only `startUrl` is required.

| Field | Default | Meaning |
| --- | --- | --- |
| `startUrl` | – | Public HTTPS site root, for example `https://example.com`. No path, query, port or credentials. |
| `maxUrlsToCheck` | 100 (1–500) | Size of the sample that is status-checked each run. |
| `maxSitemapUrls` | 5000 (1–20000) | Maximum sitemap URLs held in memory. |
| `maxSitemapFiles` | 10 (1–30) | Maximum sitemap or sitemap index files downloaded. |
| `requestDelayMillis` | 500 (250–10000) | Pause between requests. A larger `Crawl-delay` from robots.txt wins. |
| `requestTimeoutSeconds` | 15 (5–30) | Timeout per network operation. |
| `resetBaseline` | false | Discard the saved baseline and start over. |
| `stateStoreName` | `pal-sitemap-status-watch-baselines` | Named key-value store holding one baseline per domain. |

#### First-run example

Replace the placeholder with a site you own or are allowed to monitor (`example.com` itself publishes no sitemap, so it will end in `SITEMAP_NOT_FOUND`):

```json
{
    "startUrl": "https://example.com",
    "maxUrlsToCheck": 100
}
```

Run it once to create the baseline, then schedule the same input.

### Output

Each run writes to the dataset:

- one `SUMMARY` record (status, counts, sample coverage, notes, start and finish timestamps),
- one `CHANGE` record per detected change.

It also stores `OUTPUT` (the summary as JSON) and, when there are changes, `CHANGES.csv` in the run's key-value store. Run statuses: `BASELINE_CREATED`, `NO_CHANGES`, `CHANGES_DETECTED`, `FAILED`.

Structure of a change record (placeholder values for illustration only):

```json
{
    "recordType": "CHANGE",
    "domain": "example.com",
    "changeType": "NEWLY_BROKEN",
    "url": "https://example.com/some-page",
    "sourceSitemapUrl": "https://example.com/sitemap.xml",
    "previousCategory": "OK",
    "previousStatusCode": 200,
    "currentCategory": "BROKEN",
    "currentStatusCode": 404,
    "currentRedirectTarget": null,
    "redirectSameOrigin": null,
    "error": null,
    "previousCheckedAt": "2026-01-01T06:00:00Z",
    "checkedAt": "2026-01-02T06:00:00Z"
}
```

| `changeType` | Meaning |
| --- | --- |
| `NEWLY_BROKEN` | Was OK or redirecting, now 4xx/5xx or a network error. |
| `NEW_URL_BROKEN` | URL is new to the baseline and is already broken. |
| `NEWLY_REDIRECTED` | Was OK, now answers with a redirect. |
| `REDIRECT_TARGET_CHANGED` | Still redirects, but to a different target. |
| `REDIRECT_REMOVED` | Used to redirect, now answers directly. |
| `RECOVERED` | Was broken, now OK or redirecting. |

A URL that stays broken is not reported again; it is reported once when it breaks. Redirects that leave the site or downgrade to HTTP are flagged with `redirectSameOrigin: false` and are not followed.

### Scheduling

Baselines live in a **named key-value store** (`stateStoreName`), keyed by domain, so they persist across runs and are shared by every run in your account that uses the same store name. Create an Apify Schedule that runs the Actor with identical input, for example daily. A blank `stateStoreName` uses the run's default store, which only persists for local runs, not for cloud runs.

To monitor several sites, create one saved task per site root.

### Billing behavior

The code requests one pay-per-event charge named `change-report` per run, and only when the run succeeded and reported at least one change. It never requests a charge for baseline runs, no-change runs or failed runs. The payable plan and price are configured separately from this package.

### Safety and compliance

- HTTPS only, default port only, no credentials in URLs, no IP-address, localhost or reserved host names.
- DNS results are checked and the connection is pinned to the validated public address; private, loopback, link-local and similar ranges are refused.
- Only URLs on the exact same host as `startUrl` are requested. Third-party domains and cross-origin or non-HTTPS redirects are never contacted.
- No proxies, logins, cookies, contact or email harvesting. The user agent is `PALSitemapStatusWatch` and the output contains only URLs, status codes and timestamps.
- Response sizes are capped (sitemaps 5 MB, 20 MB after decompression; robots.txt 512 KB). XML with DTD or entity declarations is rejected.

### Limitations and sample-size caveats

- **It checks a sample, not every page.** With `maxUrlsToCheck` 100 on a 10,000-URL sitemap, about 1% of URLs are covered, and breakage elsewhere is invisible. The summary reports the coverage percentage; raise the limit or run separate tasks for larger sites.
- The sample is stable only while the sitemap's URL set is stable. New URLs enter the sample by hash, so some URLs may appear or drop out between runs.
- When a sitemap exceeds `maxSitemapUrls` or `maxSitemapFiles`, later URLs are not read and the summary says so.
- Only URLs listed in the sitemap are checked. Links inside pages are not crawled and page content is never inspected, so soft 404s (an error page served with status 200) are not detected.
- A redirect is recorded as one hop; chains and final status codes are not followed.
- Bot protection or rate limiting can return 403, 429 or 5xx to a monitoring client and appear as breakage. Each failing URL is retried once, and a run where at least half of the checks fail at the network level (with at least 10 checks) fails without touching the baseline. A single check is still a point-in-time observation.
- Status changes are relative to the previous successful run. Changing the input between runs (such as the sample size) changes which URLs are compared.
- If `robots.txt` is missing (404/410) the site is treated as unrestricted. Any other robots.txt failure stops the run.
- Baselines keep at most 5,000 URLs per domain.
- Sitemap files above the size caps, or crawl delays above 30 seconds, are not supported.

### Local development

```bash
pip install -r requirements.txt
python -m unittest discover -s tests -t .
```

The unit tests mock all HTTP traffic and need no network access.

# Actor input Schema

## `startUrl` (type: `string`):

Public HTTPS site root, e.g. https://practical-ai-lab.pages.dev/ . Only monitor sites you own or are permitted to audit. robots.txt is respected; do not use private addresses, credentials or unsafe URLs.

## `maxUrlsToCheck` (type: `integer`):

Size of the deterministic sample that is status-checked each run. If the sitemap is larger, a stable hash-based sample is used, so the same URLs are re-checked on later runs.

## `maxSitemapUrls` (type: `integer`):

Upper bound on sitemap URLs held in memory. Reading stops once this many are collected.

## `maxSitemapFiles` (type: `integer`):

Limit for sitemap index recursion: robots.txt is not counted, every sitemap or sitemap index file is.

## `requestDelayMillis` (type: `integer`):

Pause between requests to the site. A larger robots.txt Crawl-delay overrides this value.

## `requestTimeoutSeconds` (type: `integer`):

Timeout for each network operation.

## `resetBaseline` (type: `boolean`):

Discard the saved baseline for this domain and create a new one from this run (nothing is reported as changed).

## `stateStoreName` (type: `string`):

Named key-value store that keeps one baseline per domain between runs. Use lowercase letters, digits and hyphens (3-63 characters). Leave empty to use the run's default store, which only persists for local runs.

## Actor input object example

```json
{
  "startUrl": "https://practical-ai-lab.pages.dev/",
  "maxUrlsToCheck": 8,
  "maxSitemapUrls": 60,
  "maxSitemapFiles": 1,
  "requestDelayMillis": 500,
  "requestTimeoutSeconds": 15,
  "resetBaseline": false,
  "stateStoreName": "pal-sitemap-status-watch-baselines"
}
```

# Actor output Schema

## `results` (type: `string`):

Download rows from the latest run in JSON/CSV.

# 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 = {
    "startUrl": "https://practical-ai-lab.pages.dev/",
    "maxUrlsToCheck": 8,
    "maxSitemapUrls": 60,
    "maxSitemapFiles": 1,
    "requestDelayMillis": 500
};

// Run the Actor and wait for it to finish
const run = await client.actor("practical_ai_lab_jp/pal-website-sitemap-status-change-watch").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 = {
    "startUrl": "https://practical-ai-lab.pages.dev/",
    "maxUrlsToCheck": 8,
    "maxSitemapUrls": 60,
    "maxSitemapFiles": 1,
    "requestDelayMillis": 500,
}

# Run the Actor and wait for it to finish
run = client.actor("practical_ai_lab_jp/pal-website-sitemap-status-change-watch").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 '{
  "startUrl": "https://practical-ai-lab.pages.dev/",
  "maxUrlsToCheck": 8,
  "maxSitemapUrls": 60,
  "maxSitemapFiles": 1,
  "requestDelayMillis": 500
}' |
apify call practical_ai_lab_jp/pal-website-sitemap-status-change-watch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,practical_ai_lab_jp/pal-website-sitemap-status-change-watch"
        }
    }
}
```

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/7qVr6FGWXBnRqt8Uc/builds/Bugwst7lHiFZXTUDM/openapi.json
