# Openfda Food Enforcement (`worthwhile_loblolly/openfda-food-enforcement`) Actor

- **URL**: https://apify.com/worthwhile_loblolly/openfda-food-enforcement.md
- **Developed by:** [rx d](https://apify.com/worthwhile_loblolly) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

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

## openFDA Food Enforcement / Recall Aggregator

Fetch and filter **FDA food recall enforcement reports** from the public [openFDA Food Enforcement API](https://open.fda.gov/apis/food/enforcement/) into a clean Apify dataset.

This Actor calls `https://api.fda.gov/food/enforcement.json` only. It does **not** scrape websites, bypass rate limits, or access private data.

### Features

- Keyword search across product description, recall reason, and recalling firm
- Filters: classification (Class I / II / III), status, firm, state, country
- Date range on report / initiation / classification / termination dates
- Automatic pagination (up to 5,000 records; openFDA page size 1,000)
- Flat, analysis-ready dataset rows + run summary in key-value store
- Optional openFDA API key for higher rate limits (~240 req/min vs ~40)

### Input

| Field | Type | Description |
| --- | --- | --- |
| `keyword` | string | Free-text keyword (OR across key fields) |
| `search` | string | Raw Lucene query (AND-combined with filters) |
| `classification` | string | `Class I`, `Class II`, or `Class III` |
| `status` | string | `Ongoing`, `Terminated`, `Completed` |
| `recallingFirm` | string | Company name phrase |
| `state` / `country` | string | Firm location filters |
| `dateField` | string | Which date field the range uses |
| `dateFrom` / `dateTo` | string | `YYYYMMDD` inclusive bounds |
| `limit` | integer | Max records (1–5000, default 100) |
| `skip` | integer | Offset (max 25000) |
| `sort` | string | e.g. `report_date:desc` |
| `apiKey` | string (secret) | Optional openFDA API key |
| `includeRawOpenfda` | boolean | Keep nested `openfda` object |

#### Example input

```json
{
  "keyword": "allergen",
  "classification": "Class I",
  "dateFrom": "20240101",
  "dateTo": "20261231",
  "limit": 100,
  "sort": "report_date:desc"
}
```

### Output

Each dataset item is one recall / enforcement report, including:

`recall_number`, `event_id`, `status`, `classification`, `product_description`, `reason_for_recall`, `recalling_firm`, `city`, `state`, `country`, `distribution_pattern`, `product_quantity`, `report_date`, `recall_initiation_date`, `voluntary_mandated`, `code_info`, `fetched_at`, `source`, `source_url`.

A summary is stored as key-value record `OUTPUT_SUMMARY`.

The Actor Output schema (required by Apify Store publishing) lives in `.actor/output_schema.json` and is linked from `.actor/actor.json` as `"output"`. Dataset field layout remains in `.actor/dataset_schema.json`. After changing these files, rebuild the Actor so Publishing can detect the schema.

### Use cases

- Food-safety monitoring dashboards
- Allergen / pathogen recall alerts for retailers and brands
- Compliance research and competitive intelligence
- Downstream enrichment for AI / RAG pipelines

### Compliance & attribution

- Data source: [openFDA](https://open.fda.gov/) (U.S. Food and Drug Administration)
- [Terms of service](https://open.fda.gov/terms/) · [License](https://open.fda.gov/license/)
- Do **not** rely on openFDA alone for medical or regulatory decisions. Results may be incomplete or delayed.
- This Actor respects public API limits and retries politely on HTTP 429/5xx.

### Pricing (suggested)

Recommended monetization: **Pay-per-event (PPE)** — rental is sunset for new Actors.

Suggested events:

| Event | Suggested FREE-tier price | Notes |
| --- | --- | --- |
| `apify-actor-start` | `$0.00005` (platform default) | Covers first seconds of compute |
| `apify-default-dataset-item` | **`$0.0008` – `$0.0015`** per result | ~`$0.80`–`$1.50` per 1,000 recalls |

Offer ~10% off Silver and ~20% off Gold vs FREE. Start near `$0.001` / result; adjust after real usage.

### Changelog

#### 1.0.1

- Wire Apify Output schema (`.actor/output_schema.json`) so Store publishing can detect run output

#### 1.0.0

- Initial release: openFDA food enforcement query, filters, pagination, structured dataset

# Actor input Schema

## `search` (type: `string`):

Optional raw openFDA Lucene query. If set, it is combined with the structured filters below using AND. Example: reason_for_recall:allergen

## `keyword` (type: `string`):

Free-text keyword searched across product_description, reason_for_recall, and recalling_firm (OR). Example: peanut OR listeria

## `classification` (type: `string`):

FDA health-hazard class filter.

## `status` (type: `string`):

Recall status filter.

## `recallingFirm` (type: `string`):

Filter by recalling company name (phrase match).

## `state` (type: `string`):

US state code of the recalling firm, e.g. CA, NY, TX.

## `country` (type: `string`):

Country of the recalling firm, e.g. United States.

## `dateField` (type: `string`):

Which date field the range applies to.

## `dateFrom` (type: `string`):

Inclusive start date as YYYYMMDD, e.g. 20240101. Leave empty for no lower bound.

## `dateTo` (type: `string`):

Inclusive end date as YYYYMMDD, e.g. 20261231. Leave empty for no upper bound.

## `limit` (type: `integer`):

Maximum number of recall records to return (1–5000). openFDA allows max 1000 per request; this Actor pages automatically.

## `skip` (type: `integer`):

Number of matching records to skip before collecting (pagination offset). openFDA max skip is 25000.

## `sort` (type: `string`):

Sort field and direction, e.g. report_date:desc or recall_initiation_date:asc.

## `apiKey` (type: `string`):

Optional free openFDA API key. Without a key: ~40 req/min. With a key: ~240 req/min. Get one at https://open.fda.gov/apis/authentication/

## `includeRawOpenfda` (type: `boolean`):

If true, keep the nested openfda object on each output row (usually empty for food enforcement).

## Actor input object example

```json
{
  "search": "",
  "keyword": "allergen",
  "classification": "",
  "status": "",
  "dateField": "report_date",
  "dateFrom": "20240101",
  "dateTo": "20261231",
  "limit": 100,
  "skip": 0,
  "sort": "report_date:desc",
  "includeRawOpenfda": false
}
```

# Actor output Schema

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

Default dataset items: one row per openFDA food enforcement / recall report.

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

Key-value store record OUTPUT_SUMMARY with counts, search, and source attribution.

# 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 = {
    "search": "",
    "keyword": "allergen",
    "dateFrom": "20240101",
    "dateTo": "20261231",
    "limit": 100,
    "sort": "report_date:desc"
};

// Run the Actor and wait for it to finish
const run = await client.actor("worthwhile_loblolly/openfda-food-enforcement").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 = {
    "search": "",
    "keyword": "allergen",
    "dateFrom": "20240101",
    "dateTo": "20261231",
    "limit": 100,
    "sort": "report_date:desc",
}

# Run the Actor and wait for it to finish
run = client.actor("worthwhile_loblolly/openfda-food-enforcement").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 '{
  "search": "",
  "keyword": "allergen",
  "dateFrom": "20240101",
  "dateTo": "20261231",
  "limit": 100,
  "sort": "report_date:desc"
}' |
apify call worthwhile_loblolly/openfda-food-enforcement --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,worthwhile_loblolly/openfda-food-enforcement"
        }
    }
}
```

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/9MfMSKcrOadUrhEqJ/builds/vdG9Kwje4SlenWqI0/openapi.json
