# openFDA search - drug events, recalls, labels, devices (API) (`retrainmap/openfda-search`) Actor

Query openFDA (api.fda.gov): drug adverse events, drug and food recalls, drug labels, device events and device recalls. Pass openFDA search syntax plus a date range; get one normalised row per record (id, dates, product, classification, status, reason or reaction terms, firm) plus the raw JSON.

- **URL**: https://apify.com/retrainmap/openfda-search.md
- **Developed by:** [RetrainMap Team](https://apify.com/retrainmap) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 records

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?

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

## openFDA search — drug events, recalls, labels, devices (API)

One normalised row per openFDA record from six collections on https://api.fda.gov: drug
adverse event reports (FAERS), drug recall enforcement reports, drug labels (SPL), device
adverse event reports (MAUDE), device recalls and food recall enforcement reports. Pass any
openFDA search expression plus a date range; get record id, dates, product/drug names,
classification, status, reason or reaction terms, firm, state and country in the same
columns whichever endpoint you chose, with the record's own JSON attached — ready for CSV
or JSON.

**The default input (drug recalls, last 90 days by report date, 300 rows) succeeds within
5 minutes and returns rows** — Apify auto-tests it daily.

### Data source and status

| | |
|---|---|
| Publisher | U.S. Food and Drug Administration — openFDA (https://open.fda.gov) |
| API | https://api.fda.gov/{drug,device,food}/… — public; an API key is optional (https://open.fda.gov/apis/authentication/). Without a key: 1,000 requests per day per IP, 240 per minute; with a key: 120,000 per day |
| What this Actor reads | Plain GET requests with `search=(your query) AND <date_field>:[from TO to]`, `sort=<date_field>:desc`, `limit=100`, `skip=N`, at most two requests per second; the key, when given, is sent only as the `api_key` query parameter and never logged or written to the dataset |
| Refresh cadence | openFDA refreshes each collection on its own schedule (enforcement reports and labels roughly weekly, FAERS and MAUDE files roughly quarterly/monthly — see https://open.fda.gov/apis/). The Actor reads live on every run; the API's own `last_updated` for the endpoint is stored in `RUN_SUMMARY`, and `fetched_at` on each row is the fetch time |
| Copyright | Works of the United States Government are not subject to copyright in the U.S. (17 U.S.C. §105); openFDA data are released under the terms at https://open.fda.gov/license/. Please cite openFDA as the source |
| Known caveats | One query returns at most 25,100 records (openFDA rejects `skip` above 25,000) — narrow the search or dates for more; "no matches" is the API's HTTP 404 and yields zero rows with a warning; a malformed search expression makes the API answer HTTP 500 and the run fails with the API's message; the `state` column is empty for FAERS and labels (the API carries none); `raw_json` is trimmed to 6,000 characters (`raw_json_truncated` says when) |

Honesty note: openFDA data are unvalidated per the API's own disclaimer and are
**informational, not medical advice** — the rows are the API's own fields mapped to a common
set, nothing is inferred, summarised or classified by this Actor, and a run stops with an
error rather than guess when the API's shape changes.

Identification: the requests carry a product-token User-Agent
(`SteelyardActor/0.1 (openfda-search; …)` — api.fda.gov's WAF rejects any agent string
containing "nmap", which the brand name RetrainMap does) and the operator's contact address in
the standard `From:` header (RFC 9110 §10.1.2).

### Input

| Field | Type | Meaning |
|---|---|---|
| `endpoint` | select | `drug_enforcement` (default), `drug_event`, `drug_label`, `device_event`, `device_recall`, `food_enforcement` |
| `search` | string | Optional openFDA search expression in the endpoint's own field names, e.g. `patient.drug.medicinalproduct:"ibuprofen"`, `classification:"Class I" AND state:CA` |
| `date_field` | string | Optional; default per endpoint: `receivedate`, `report_date`, `effective_time`, `date_received`, `event_date_posted`, `report_date` |
| `date_from` / `date_to` | `YYYY-MM-DD` | Optional, inclusive. Both empty = the last 90 days; only `date_from` = through today; only `date_to` = from 1900-01-01 |
| `max_records` | integer | Default 300, at most 25,100 |
| `api_key` | secret string | Optional openFDA key |
| `request_interval_ms` | integer | Default 500 (floor 250) |
| `contact_email` | string | Sent in the `From:` header |

Example — FAERS reports naming ibuprofen received since January 2026:

```json
{ "endpoint": "drug_event", "search": "patient.drug.medicinalproduct:\"ibuprofen\"", "date_from": "2026-01-01", "max_records": 500 }
```

### Output (dataset row)

Common columns for every endpoint: `endpoint`, `endpoint_path`, `record_id`, `record_id_field`
(which field the id came from — for recalls not yet classified `recall_number` is empty and
`event_id` is used instead), `date_field`,
`date` (the date field's value, `YYYY-MM-DD`), `secondary_date`, `product`, `generic_names`
(list), `classification`, `status`, `reason_or_terms`, `firm`, `state`, `country`,
`source_url` (the openFDA page query the record came from, without any key), `raw_json`
(the record's JSON, ≤ 6,000 characters), `raw_json_truncated`, `fetched_at`.

How the common columns are filled per endpoint:

| Endpoint | `record_id` | `date` / `secondary_date` | `product` / `generic_names` | `classification` / `status` | `reason_or_terms` | `firm` |
|---|---|---|---|---|---|---|
| drug\_enforcement, food\_enforcement | `recall_number` | `report_date` / `recall_initiation_date` | `product_description` / `openfda.generic_name` | `classification` (Class I–III) / `status` | `reason_for_recall` | `recalling_firm` |
| drug\_event | `safetyreportid` | `receivedate` / `receiptdate` | drug `medicinalproduct` names / active substances | `serious` (1 = Serious, 2 = Not serious) / seriousness flags set (death, hospitalization, …) | MedDRA reaction terms | `sender.senderorganization` |
| drug\_label | `set_id` | `effective_time` / — | `openfda.brand_name` / `openfda.generic_name` | `openfda.product_type` / label `version` | `purpose` or `indications_and_usage` | `openfda.manufacturer_name` |
| device\_event | `mdr_report_key` | `date_received` / `date_of_event` | device `brand_name` / `generic_name` | `event_type` / `type_of_report` | `product_problems` | manufacturer name |
| device\_recall | `product_res_number` | `event_date_posted` / `event_date_initiated` | `product_description` / `openfda.device_name` | `openfda.device_class` / `recall_status` | `reason_for_recall` | `recalling_firm` |

Text columns are trimmed to 1,000 characters; the full record is in `raw_json`. A run
summary (query, the API's own match count and `last_updated`, pages, requests, whether the
skip ceiling or the pay-per-event budget stopped the run) is stored as `RUN_SUMMARY` in the
run's key-value store.

### Pricing (pay per event)

| Event | Price |
|---|---|
| `run-start` — once per run | $0.10 |
| `record` — per row written | $0.005 |

The default pull (≤ 300 rows) costs at most $1.60; 1,000 records cost $5.10. Rows stop when
your run's maximum charge is reached; the run summary says so.

### Operator

Steelyard Ventures LLC (RetrainMap) — info@steelyardclinical.com. Not affiliated with the
U.S. Food and Drug Administration. The Actor writes only to its own dataset and key-value
store; it stores no credentials and sends nothing else.

# Actor input Schema

## `endpoint` (type: `string`):

Which openFDA collection to query. Default date field per endpoint: drug\_event = receivedate, drug\_enforcement = report\_date, drug\_label = effective\_time, device\_event = date\_received, device\_recall = event\_date\_posted, food\_enforcement = report\_date.

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

Optional openFDA search expression, e.g. patient.drug.medicinalproduct:"ibuprofen" or classification:"Class I" AND state:CA. Field names are the endpoint's own (see https://open.fda.gov/apis/). The date range is appended with AND. Empty = date range only.

## `date_field` (type: `string`):

Optional. The endpoint field the date range and the newest-first sort apply to (letters, digits, dots, underscores). Empty = the endpoint's default date field listed above.

## `date_from` (type: `string`):

Optional, inclusive. When both dates are empty the Actor uses the last 90 days (today minus 90 days through today, UTC). If only date\_to is given, date\_from becomes 1900-01-01.

## `date_to` (type: `string`):

Optional, inclusive. If only date\_from is given, date\_to becomes today (UTC).

## `max_records` (type: `integer`):

Stop after this many records have been written. openFDA pages with limit=100 and skip, and rejects skip above 25,000, so one query can return at most 25,100 records - narrow the search or the dates for more.

## `api_key` (type: `string`):

Optional. Without a key openFDA allows 1,000 requests per day per IP (240 per minute); with a free key from https://open.fda.gov/apis/authentication/ it allows 120,000 per day. Sent only as the api\_key query parameter; never logged or written to the dataset.

## `request_interval_ms` (type: `integer`):

Politeness delay towards api.fda.gov. Each request returns up to 100 records; the floor is 250 ms.

## `contact_email` (type: `string`):

Sent in the standard From: request header so the data owner can reach the operator (RFC 9110 s10.1.2).

## Actor input object example

```json
{
  "endpoint": "drug_enforcement",
  "max_records": 300,
  "request_interval_ms": 500,
  "contact_email": "info@steelyardclinical.com"
}
```

# Actor output Schema

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

Every matched openFDA record as one normalised row with the raw JSON attached.

## `results_csv` (type: `string`):

The same rows as a CSV file.

# 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("retrainmap/openfda-search").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("retrainmap/openfda-search").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 retrainmap/openfda-search --silent --output-dataset

```

## MCP server setup

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

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/RjFUwAlSDTpNXZ299/builds/YQBY2GtG4CyaWlLot/openapi.json
