# Nyc Open Data Scraper (`bigibyte/nyc-open-data-scraper`) Actor

Easily search and extract US federal grant opportunities by keyword or ID. Track deadlines, open status, agencies, and listing numbers without logging in. Results export seamlessly to JSON, CSV, or Excel datasets on Apify.

- **URL**: https://apify.com/bigibyte/nyc-open-data-scraper.md
- **Developed by:** [BigiByte](https://apify.com/bigibyte) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

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

### NYC Open Data Scraper: 311, Permits, and Inspections

<p align="center">
  <img src="https://imgur.com/M6o2PBA.png" alt="Nyc Open Data" style="max-width:100%; border-radius:14px; width:680px;" />
</p>

Extract NYC 311 service requests, restaurant inspections, and other municipal datasets into structured tables. Filter records using custom parameters, explore the NYC dataset catalog, and download your data in JSON, CSV, or Excel formats.

### Use cases

- 311 Extracts: Pull complaint types, descriptors, ZIP codes, addresses, and responsible agencies for municipal service requests.
- Restaurant Inspections: Export CAMIS numbers, business names (DBA), borough details, and inspection dates.
- Permits & Custom Datasets: Point the scraper at any known NYC 311 or city dataset ID.
- Catalog Search: Search for specific city datasets by keyword before exporting full records.
- Filtering & Sorting: Apply queries and sort orders when custom data subsets are needed.
- Scheduled Exports: Set up recurring runs to download fresh, updated datasets on a schedule.

### What the scraper extracts

- Rows Mode: Saves structured records for the requested dataset. The default overview includes fields such as unique key, creation date, agency, complaint type, descriptor, ZIP code, and incident address.
- Catalog Mode: Saves matching entries from catalog searches. Key details include dataset title, writeup, resource category, publisher attribution, and view stats.

### Dataset fields vary depending on the schema. For example:

- 311 Records: Retain service-request properties like complaint type, locations, and timestamps.
- Restaurant Inspection Records: Retain inspection-specific details such as CAMIS ID, business name, borough, building, street, ZIP code, phone, inspection date, violation flags, and coordinates.

### Input Parameters

Parameter | Type | Default | Description
\--- | --- | --- | ---
mode | string | rows | Choose `rows` for record extraction or `catalog` for dataset search.
datasetId | string | erm2-nwe9 | The NYC dataset ID for `rows` mode (e.g., `erm2-nwe9` for 311 requests, `43nn-pn8j` for restaurant inspections).
query | string | restaurant | Search keyword used when running in `catalog` mode.
where | string | empty | Custom filter condition for dataset queries.
order | string | :id | Sort order for extracted records.
maxItems | integer | 100 | Maximum number of rows to collect (capped at 1,000).
timeoutSecs | integer | 300 | Total maximum runtime in seconds.
requestTimeoutSecs | integer | 30 | Timeout per request in seconds.
proxyConfiguration | object | no proxy | Optional proxy setup. Default is `{"useApifyProxy": false}`.

### Example input (Rows mode):

```json
{
    "mode": "rows",
    "datasetId": "erm2-nwe9",
    "where": "complaint_type = 'Street Condition'",
    "order": ":id",
    "maxItems": 100,
    "timeoutSecs": 300,
    "requestTimeoutSecs": 30,
    "proxyConfiguration": { "useApifyProxy": false }
}

```

### Example input (Catalog mode):

```json
{
    "mode": "catalog",
    "query": "restaurant",
    "maxItems": 20
}

```

### Output Example

```json
{
    "unique_key": "70702319",
    "created_date": "2026-10-10T03:03:53.000",
    "agency": "DOT",
    "agency_name": "Department of Transportation",
    "complaint_type": "Street Condition",
    "descriptor": "Pothole",
    "incident_zip": "11377",
    "incident_address": "47 STREET",
    "street_name": "47 STREET",
    "cross_street_1": "48 AVENUE",
    "cross_street_2": "50 AVENUE",
    "address_type": "BLOCKFACE",
    "city": "QUEENS",
    "facility_type": "N/A",
    "scrapedAt": "2026-10-12T00:00:00+00:00"
}

```

### Field Descriptions

- unique_key: Unique identifier for the record or catalog entry (used for deduplication).
- created_date: Creation or record timestamp.
- agency / agency_name: Responsible city agency or department.
- complaint_type / descriptor: Type and description of the reported issue.
- incident_zip / incident_address / street_name: Location details for the record.
- camis / dba: Inspection ID and business name for restaurant data.
- datasetName / recordText / recordKind: Catalog dataset title, description, and item category.
- pageViewsTotal: Total view count for catalog items.
- scrapedAt: UTC timestamp indicating when the data was scraped.
- error: Present only on failed record processing turns.

### Pagination & Execution Rules

- Records are gathered page-by-page (100 items per batch) until `maxItems` is reached.
- Duplicate entries are automatically identified and skipped.
- If a dataset query returns no additional items, the run concludes cleanly.
- Network requests are spaced out smoothly (~0.75 seconds apart) to keep traffic steady and avoid unnecessary request failures. Transient errors are retried automatically up to 3 times before moving on.
- Total items per run are capped at 1,000.

### FAQ

How do I export restaurant inspections?
Set `mode` to `rows` and use `43nn-pn8j` as the `datasetId`.

How many records can I collect per run?
You can request up to 1,000 records per execution.

What happens if a query filter contains a syntax error?
The actor logs an error record describing the issue without crashing the overall process.

Can I download the results as Excel or CSV?
Yes, once the run completes, you can export your data format directly as JSON, CSV, or Excel.

To learn more, read Apify's guide: [Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/)

# Actor input Schema

## `mode` (type: `string`):

rows reads a Socrata 4x4 on data.cityofnewyork.us. catalog searches the NYC catalog API.

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

Socrata 4x4 used in rows mode. erm2-nwe9 is 311 service requests. 43nn-pn8j is restaurant inspections. Ignored in catalog mode.

## `query` (type: `string`):

Search text sent as q to the NYC catalog endpoint. Used only in catalog mode.

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

Optional SoQL $where filter for rows mode. Leave empty to skip the filter. Ignored in catalog mode.

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

SoQL $order for rows mode. Default is :id. Leave empty to omit $order. Ignored in catalog mode.

## `appToken` (type: `string`):

Optional Socrata application token sent as the X-App-Token header. Leave empty for the public shared pool. The token is not written into rows or source URLs.

## `maxItems` (type: `integer`):

Maximum result rows to save this run. Hard cap is 1000.

## `timeoutSecs` (type: `integer`):

Stop the run after this many seconds. Default is 300. Maximum is 3600.

## `requestTimeoutSecs` (type: `integer`):

How long to wait for one HTTP response before retrying. Default is 30 seconds.

## `proxyConfiguration` (type: `object`):

Optional proxy for requests. Default is no proxy. Leave it off so calls stay on the public Socrata pool.

## Actor input object example

```json
{
  "mode": "rows",
  "datasetId": "erm2-nwe9",
  "query": "restaurant",
  "where": "complaint_type = 'Street Condition'",
  "order": ":id",
  "maxItems": 100,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

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

No description

## `datasetUrl` (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 = {
    "mode": "rows",
    "datasetId": "erm2-nwe9",
    "query": "restaurant",
    "order": ":id",
    "maxItems": 100,
    "timeoutSecs": 300,
    "requestTimeoutSecs": 30,
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("bigibyte/nyc-open-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 = {
    "mode": "rows",
    "datasetId": "erm2-nwe9",
    "query": "restaurant",
    "order": ":id",
    "maxItems": 100,
    "timeoutSecs": 300,
    "requestTimeoutSecs": 30,
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("bigibyte/nyc-open-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 '{
  "mode": "rows",
  "datasetId": "erm2-nwe9",
  "query": "restaurant",
  "order": ":id",
  "maxItems": 100,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call bigibyte/nyc-open-data-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,bigibyte/nyc-open-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/dUU5I6Pl4Be92W63o/builds/GgLocMviWGanacZV8/openapi.json
