# Chicago Building Violations Scraper (`muhammadafzal/chicago-building-violations-scraper`) Actor

Query the official City of Chicago Building Violations dataset by address, status, violation code, inspection, date range, or advanced SoQL filters. Returns one normalized record per building violation.

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

## Pricing

from $1.00 / 1,000 violation record returneds

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/platform/actors/running/actors-in-store#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

## Chicago Building Violations Scraper

Query the official City of Chicago Building Violations dataset through its public Socrata API. The actor returns one normalized dataset item per violation and stores a run summary in the `OUTPUT` key-value record.

### What it returns

Each result includes the City violation ID, violation and inspection details, address fields, property group, coordinates, computed community/ZIP/ward identifiers, the official API URL, and the UTC retrieval time. Null values are preserved when the City dataset does not provide a field.

The source dataset is [Building Violations (22u3-xenr)](https://data.cityofchicago.org/Buildings/Building-Violations/22u3-xenr). It contains Department of Buildings violations from 2006 to the present. The City notes that the data is historical and informational; it should not be used as a substitute for title commitments, court records, or a current property-condition inspection.

### Example input

The default query returns up to 100 `OPEN` violations:

```json
{
  "violationStatus": "OPEN",
  "maxResults": 100
}
```

Find violations near an address over a date range:

```json
{
  "address": "121 N LA SALLE",
  "violationDateFrom": "2024-01-01",
  "violationDateTo": "2024-12-31",
  "maxResults": 250
}
```

Filter an entire property group or inspection:

```json
{
  "propertyGroup": "92840",
  "inspectionNumber": "14930108",
  "maxResults": 100
}
```

For advanced use, `where` accepts one Socrata `$where` expression using the official field names, for example `street_type = 'AVE' AND inspection_status = 'FAILED'`. Do not include `$where=` in the value.

### Inputs and limits

- `address`: case-insensitive address substring.
- `propertyGroup`: exact Property Group identifier.
- `violationStatus`: `OPEN`, `COMPLIED`, or `NO ENTRY`; defaults to `OPEN`.
- `violationCode`: exact violation code.
- `inspectionNumber`: exact inspection number.
- `inspectionCategory`: `COMPLAINT`, `PERIODIC`, `PERMIT`, or `REGISTRATION`.
- `violationDateFrom` and `violationDateTo`: inclusive `YYYY-MM-DD` date range.
- `where`: optional advanced SoQL filter.
- `order`: `newest` or `oldest` violation date.
- `maxResults`: 1–5,000 records; default 100.
- `pageSize`: 1–1,000 API rows per page; default 500.

The actor uses the public City endpoint directly, does not require an API key, and does not use browser automation or private data. API errors are reported honestly in `OUTPUT`; partial results remain available when a later page fails.

### Pricing

This Actor uses pay-per-event pricing with platform usage included:

| Event | Price |
| --- | ---: |
| Actor start | $0.00005 per start event |
| Violation record returned | $0.0005 per dataset item |

The default 100-record run costs at most approximately **$0.05005**, excluding any later dataset storage or access costs. Valid empty or invalid-input runs do not create dataset-item charges.

### Local development

```bash
npm install
npm test
npm start
```

The `start` command expects Apify Actor input/storage environment variables. For a quick local API smoke test after building, use the Apify local runner or run the compiled code with a local `INPUT.json`/storage configuration.

# Actor input Schema

## `address` (type: `string`):

Return violations whose Chicago address contains this text, for example "121 N LA SALLE". Matching is case-insensitive.

## `propertyGroup` (type: `string`):

Exact Chicago Property Group identifier.

## `violationStatus` (type: `string`):

Filter by current violation status. OPEN is prefilled for a useful default query.

## `violationCode` (type: `string`):

Exact Department of Buildings violation code, such as CN138106.

## `inspectionNumber` (type: `string`):

Exact Chicago building inspection number.

## `inspectionCategory` (type: `string`):

Filter by COMPLAINT, PERIODIC, PERMIT, or REGISTRATION. Leave blank to include all categories.

## `violationDateFrom` (type: `string`):

Inclusive start date in YYYY-MM-DD format.

## `violationDateTo` (type: `string`):

Inclusive end date in YYYY-MM-DD format.

## `where` (type: `string`):

Optional advanced Socrata $where expression using official field names. Do not include $where=.

## `order` (type: `string`):

Sort by newest or oldest violation date.

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

Maximum number of violation records to return.

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

Number of records requested per Socrata API page.

## Actor input object example

```json
{
  "address": "",
  "propertyGroup": "",
  "violationStatus": "OPEN",
  "violationCode": "",
  "inspectionNumber": "",
  "inspectionCategory": "",
  "violationDateFrom": "",
  "violationDateTo": "",
  "where": "",
  "order": "newest",
  "maxResults": 100,
  "pageSize": 500
}
```

# Actor output Schema

## `dataset` (type: `string`):

Normalized Chicago building violation records written to the default dataset.

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

Record counts, filters, query URL, truncation state, and warnings stored in OUTPUT.

# 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/chicago-building-violations-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/chicago-building-violations-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/chicago-building-violations-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,muhammadafzal/chicago-building-violations-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/VRc0tb7T4cnaKQz5z/builds/RGStw9cWmCAHvVJeQ/openapi.json
