# LAPD Crime Data Scraper – NIBRS & Legacy (`muhammadafzal/lapd-crime-data-scraper`) Actor

Extract LAPD NIBRS and legacy crime records for research and data pipelines. Filter by date, LAPD area, offense, or search term. Returns normalized IDs, offense details, dates, locations, coordinates, status, counts, and raw source fields.

- **URL**: https://apify.com/muhammadafzal/lapd-crime-data-scraper.md
- **Developed by:** [Muhammad Afzal](https://apify.com/muhammadafzal) (community)
- **Categories:** Other, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 lapd crime records

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## LAPD Crime Data Scraper

Extract public Los Angeles Police Department crime records from the City of Los Angeles Open Data Portal. The Actor uses the official Socrata JSON endpoint and returns one normalized dataset item per source row.

### Modes

- `nibrs` (default): current consolidated LAPD NIBRS offense records, dataset `k7nn-b2ep`.
- `legacy`: historical 2020–2024 incident records, dataset `2nrs-mtv8`. LAPD says this legacy dataset is no longer updated after its transition to NIBRS reporting.

Filter by inclusive occurrence dates, exact LAPD area name, partial offense text, or a combined search term. `maxResults` is a hard output and result-charge cap. The `raw` field preserves the source row for fields that do not fit the normalized contract.

Example:

```json
{
  "datasetMode": "nibrs",
  "startDate": "2025-01-01",
  "endDate": "2025-01-31",
  "areaName": "Central",
  "offense": "robbery",
  "maxResults": 25
}
```

### Output and pricing

Each result includes case/incident identifiers, offense fields, dates, area, hundred-block location, coordinates when supplied, status, counts, source URL, and raw source data. `OUTPUT` contains run status, pagination diagnostics, warnings, and charged event counts.

The Actor charges `$0.001` per stored crime record after the dataset write succeeds. Empty, invalid, and failed requests do not charge result events. A run-start event may be configured separately by Apify.

### Limitations and responsible use

LAPD records describe reported incidents and may contain transcription or coverage limitations. Addresses are generalized to the nearest hundred block and coordinates may represent that generalized location. This Actor is not for emergency information, individual criminal-history checks, personally identifying information, or legal conclusions. Respect the City of Los Angeles data terms and avoid inferring that missing or zero results mean no crime occurred.

Source: [Los Angeles Open Data Portal](https://data.lacity.org/) and [LAPD crime-data documentation](https://dev.socrata.com/foundry/data.lacity.org/2nrs-mtv8).

### What data does LAPD Crime Data Scraper return?

Results are written to the default Apify dataset or the output links declared by the Actor. Inspect the dataset schema and a small test run before building a production mapping.

### Use cases

- Schedule repeatable collection and export results to downstream workflows.
- Run a one-off research job and export the structured result as JSON, CSV, Excel, XML, or RSS from Apify.
- Schedule the same input to monitor changes over time and send completed datasets to a webhook or integration.
- Feed schema-shaped records into a database, spreadsheet, BI tool, or AI workflow with the source URL retained for verification.

### Input

| Field | Type | Description |
|---|---|---|
| `datasetMode` | string | Use nibrs for current consolidated LAPD NIBRS offense records, or legacy for historical 2020–2024 incident records. |
| `datasetId` | string | Optional public Socrata dataset ID in the form xxxx-xxxx. Leave blank to use the mode default. |
| `startDate` | string | Optional inclusive occurrence date in YYYY-MM-DD format. |
| `endDate` | string | Optional inclusive occurrence date in YYYY-MM-DD format. |
| `areaName` | string | Optional exact LAPD area name, such as Hollywood, Wilshire, or Central. |
| `offense` | string | Optional case-insensitive partial match against the offense description, such as burglary, robbery, or assault. |
| `searchTerm` | string | Optional case-insensitive partial match against offense description or LAPD area name. |
| `maxResults` | integer | Maximum unique records to return and charge for. This is a hard output and cost cap. |
| `pageSize` | integer | Socrata page size. Larger pages are faster; lower values reduce response size. |
| `requestDelayMs` | integer | Delay between paginated source requests. Use this to be gentle with the public open-data service. |

### Run LAPD Crime Data Scraper with the Apify API

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

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('muhammadafzal/lapd-crime-data-scraper').call({
  "datasetMode": "nibrs",
  "maxResults": 25,
  "pageSize": 1000,
  "requestDelayMs": 100
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

You can also run the Actor from Apify Console, schedules, webhooks, the REST API, Make, Zapier, n8n, or the hosted Apify MCP server.

### Support

When reporting a problem, include the **Actor run ID**, a redacted input, the expected result, and a small public example URL when applicable. Do not post API tokens, cookies, credentials, or personal data in an issue.

# Actor input Schema

## `datasetMode` (type: `string`):

Use nibrs for current consolidated LAPD NIBRS offense records, or legacy for historical 2020–2024 incident records.

## `datasetId` (type: `string`):

Optional public Socrata dataset ID in the form xxxx-xxxx. Leave blank to use the mode default.

## `startDate` (type: `string`):

Optional inclusive occurrence date in YYYY-MM-DD format.

## `endDate` (type: `string`):

Optional inclusive occurrence date in YYYY-MM-DD format.

## `areaName` (type: `string`):

Optional exact LAPD area name, such as Hollywood, Wilshire, or Central.

## `offense` (type: `string`):

Optional case-insensitive partial match against the offense description, such as burglary, robbery, or assault.

## `searchTerm` (type: `string`):

Optional case-insensitive partial match against offense description or LAPD area name.

## `maxResults` (type: `integer`):

Maximum unique records to return and charge for. This is a hard output and cost cap.

## `pageSize` (type: `integer`):

Socrata page size. Larger pages are faster; lower values reduce response size.

## `requestDelayMs` (type: `integer`):

Delay between paginated source requests. Use this to be gentle with the public open-data service.

## Actor input object example

```json
{
  "datasetMode": "nibrs",
  "maxResults": 25,
  "pageSize": 1000,
  "requestDelayMs": 100
}
```

# Actor output Schema

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

No description

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

No description

# 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("muhammadafzal/lapd-crime-data-scraper").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("muhammadafzal/lapd-crime-data-scraper").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 muhammadafzal/lapd-crime-data-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,muhammadafzal/lapd-crime-data-scraper"
        }
    }
}

```

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/uo1SwNEwyBvLfOJcK/builds/cB5cPhIxz1unYoMMR/openapi.json
