# FDA Shortage Catalog Reconciler (`technicaldost/fda-shortage-catalog-reconciler`) Actor

Reconcile catalog package NDCs against the official FDA shortage snapshot. Preserve row IDs, exact source evidence, unmatched rows and ambiguous-code diagnostics. No stock, substitution or medical-care recommendations.

- **URL**: https://apify.com/technicaldost/fda-shortage-catalog-reconciler.md
- **Developed by:** [Technical Dost Solutions](https://apify.com/technicaldost) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 unique reconciled ndcs

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?

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

## FDA Shortage Catalog Reconciler

Reconcile an inventory catalog against the **top-level package identifiers in the official openFDA drug-shortages database**. Get one result per input row, with your opaque row ID, explicit unmatched/invalid/ambiguous outcomes, source statuses, source publication date, and selected unchanged source evidence.

For pharmacy integration developers and inventory-data teams. This is a bounded reconciliation job, not another watchlist, alert feed, manufacturer directory, or medical recommendation engine.

**Do not use these results for clinical decisions.** `exactMatch` means a database record matched, not that a product is currently in shortage. FDA records include Current, Resolved and discontinued statuses. `noListedRecord` does not establish safety, availability, FDA approval, or absence of a shortage. FDA says its API results are unvalidated. Consult official FDA records and suppliers. Data is not real-time.

### Quick start

Use the prefilled example, or submit:

```json
{"rows":[
  {"rowId":"stock-001","packageNdc":"0228-2551-06","format":"ndc10"},
  {"rowId":"stock-002","packageNdc":"76045021010","format":"ndc11"},
  {"rowId":"stock-003","packageNdc":"0228255106","format":"ndc10"}
]}
```

1. Supply 1–1000 rows. Every row has `rowId`, `packageNdc`, and `format`.
2. Set a run event budget covering all prospective unique valid codes: $0.002 each, maximum $2.00 for 1000. Platform usage is separate. Insufficient budget fails before fetching/output; it does not silently truncate the catalog.
3. Run, inspect `RUN_SUMMARY.status`, and only accept the whole dataset when it is `completed` and `resultsWritten` equals your input length.
4. Export JSON for nested evidence; CSV is useful for row status and source-status review. Join by `inputIndex` plus `rowId`. Duplicate row IDs and codes are preserved; they are not unique row keys.

Use opaque catalog/SKU IDs. **Never send patient identifiers, prescriptions, patient history, or other patient information.** The Actor rejects extra input fields. Your input stays on Apify; requests to FDA contain only fixed pagination parameters, never your NDCs or row IDs. No API key or proxy is required. No arbitrary URLs are accepted.

### Identifier rules and ambiguity

- `ndc10`: hyphenated 4-4-2, 5-3-2, or 5-4-1. The short segment is left-padded with zero to produce an internal 5-4-2 comparison/billing key. No trimming, punctuation repair, fuzzy search, or numeric coercion.
- Bare ten digits are `ambiguousCode`: removing hyphens loses the segment layout. Supply the package label's segmented identifier.
- `ndc11`: explicitly declared eleven digits or 5-4-2. A unique possible NDC10 inverse is required. If zeros permit multiple inverse segment layouts, or none, return `ambiguousCode` uncharged. This deliberately rejects some legitimate billing codes rather than guessing. Supply the labeled NDC10 instead.
- Some official source records themselves use 5-4-2. An unambiguous source NDC11 is compared with the correctly normalized input, so format differences do not create false unmatched results. An ambiguous source NDC11 that might correspond to a valid input yields `ambiguousCode`, includes candidate evidence, and is uncharged. Candidate evidence is not a confirmed match; `matchedPackageNdc` and `matchBasis` are null.
- Distinct segmented NDC10 packages that collide after zero-padding are never treated as the same confirmed package. Matching segmented input selects its own exact segmented code and any unambiguous equivalent source NDC11. All matching source rows, including duplicates and multiple statuses, are retained.
- **Only top-level `package_ndc` is match evidence.** FDA's `openfda.package_ndc` harmonization can contain other packages; those are not automatically affected packages and are never used for matching.
- Twelve-digit NDCs are currently unsupported and return `invalidCode`, never `noListedRecord`. FDA's uniform 12-digit transition takes effect March 7, 2033. A new unsupported source format fails the whole snapshot rather than producing false negatives. [FDA format transition](https://www.fda.gov/drugs/electronic-drug-registration-and-listing-system-edrls/national-drug-code-format). [FDA explanation of 10-to-11-digit padding](https://www.fda.gov/media/173715/download).

### Results

| Field | Meaning |
|---|---|
| `inputIndex`, `rowId`, `packageNdc`, `format` | Original catalog order and supplied identifiers |
| `status` | `exactMatch`, `noListedRecord`, `invalidCode`, or `ambiguousCode` |
| `normalizedNdc11` | Comparison/billing key when derivable; not proof of drug identity |
| `matchedPackageNdc`, `sourcePackageNdcs` | First confirmed source code and all source codes; candidate arrays may be present for source ambiguity |
| `sourceStatuses` | Every distinct source status; do not assume Current |
| `matchBasis`, `reason` | Exact/equivalent matching rule, or reason for invalid/ambiguous/unmatched outcome |
| `sourceRecords` | Selected unchanged fields for all matching records, or clearly flagged ambiguity candidates |
| `sourceLastUpdated`, `fetchedAt`, `snapshotSha256` | FDA publication date, fetch completion time, full snapshot multiset fingerprint |
| `sourceUrl`, `disclaimer` | Official API and interpretation warning |

Source evidence allowlist: package identifier, status, generic/company name, dosage form, presentation, update/initial/discontinued/resolved dates, therapeutic category, update type and shortage reason, when supplied by FDA. Contact information, free-form related-info text and harmonized `openfda` arrays are omitted. Source values are not rewritten or clinically interpreted. No personal contact harvesting. The full raw snapshot is transient, not exported; its fingerprint covers all raw fields.

### Snapshot correctness and hard limits

Before emitting any results for valid codes, the Actor checks API robots.txt, then reads the full source **twice**. It requires equal totals, publication dates and complete record multisets including duplicates. There is no official transactional snapshot guarantee: two agreeing scans reduce, but cannot mathematically eliminate, upstream pagination races. If data changes between scans, rerun later.

- Fixed `https://api.fda.gov/drug/shortages.json`; 1000 records per page, maximum 10,000 source records.
- Refuses short/malformed pages, missing package/status fields, unexpected NDC formats, inconsistent counts, changing snapshots, empty source, or data published more than **14 UTC calendar days ago**. Same-day data is accepted across UTC midnight; future publication dates are rejected. This threshold does not guarantee freshness of any individual record.
- At most 65 requests including robots/retries, 2 requests/second, 3 attempts per request, 20-second request timeout, 180-second overall source deadline. Maximum 12 MB per JSON page, 256 KB robots, 80 MB total response data. Retries for transient network failures,429 and selected5xx only; bounded Retry-After is honored, long waits fail.
- Redirects are forbidden. robots404/410 permits the official API; an explicit disallow, unknown/error response, or suspicious HTML robots file aborts. No proxy rotation or bypassing access controls.
- [FDA anonymous limits](https://open.fda.gov/apis/authentication/): 240 requests/minute and1000/day/IP. Concurrent jobs sharing an IP may exhaust limits; the Actor does not evade them. A 1598-record snapshot needs five requests including robots, absent retries. Avoid high-frequency scheduling.

Source failures produce a failed run and summary, **not** `noListedRecord`. No result fees are charged before snapshot verification. Invalid-only batches do not access FDA and have no result-event charges.

### Pricing and integration

**$0.002 per unique valid NDC successfully reconciled, no start fee.** Both exact matches and useful verified `noListedRecord` outcomes count. Repeated input rows and equivalent accepted formats share one normalized-NDC charge per run. Invalid codes, input ambiguity, and source ambiguity are uncharged. Running the same catalog again is a new reconciliation and billed again. This is not a clinical price or product availability fee.

- 1 unique reconciled code: $0.002 in result fees.
- 100 unique reconciled codes: $0.20.
- 1000 unique reconciled codes: $2.00.
- **Apify platform usage is paid separately by the user**, including failed, empty and invalid-only runs. Small batches have proportionally higher usage overhead because a full source snapshot is required. Actual usage depends on runtime and platform rates; examples are not all-in quotes.

The runtime verifies exactly one configured event, `reconciled-ndc`, at $0.002 and refuses pricing drift or additional charged event types. It preflights the full prospective budget, then uses `Actor.pushData(row, eventName)` once per newly reconciled canonical code. Other rows are pushed without that event. No separate/manual duplicate charge call. Event-specific SDK count is verified; zero-charge delivery does not claim completion. Uncertain dataset/charge writes are never retried. A failed output phase may leave partial rows and incurred fees: inspect `RUN_SUMMARY` and never treat a failed run's dataset as complete. As with all cloud workloads, interrupted/killed runs are not resumable transactional deliveries.

REST integration: start this Actor with the example JSON as input through Apify's Run Actor API, poll the run to completion, then retrieve its default dataset and `RUN_SUMMARY` from the default key-value store. Use your Apify credentials in the authorization header, never in input rows. SDK clients can use the Actor's run `defaultDatasetId` and `defaultKeyValueStoreId`. Require both Apify run success and summary `completed` before importing. No patient data, notifications or substitutions are generated.

### Data source and rights

Data provided by the U.S. Food and Drug Administration ([openFDA](https://open.fda.gov)). This independent Actor is not affiliated with or endorsed by FDA. [Terms](https://open.fda.gov/terms/) generally dedicate openFDA materials to CC0, including commercial use, with exceptions for explicitly marked third-party works. Users must respect applicable terms and restrictions. Use of the API accepts its terms; no guarantee of accuracy, uptime or medical suitability is made.

### Development

Node22 image `apify/actor-node:22`; dependencies pinned in package-lock.json. `npm ci`, `npm test`, `npm run validate`. `npm run smoke` performs the bounded read-only live verification and saves a local report; it does not bill or publish. On a local Node24 environment that requires an existing HTTPS proxy, `NODE_USE_ENV_PROXY=1 npm run smoke` uses the environment's configured transport. Production runs use normal native fetch on Apify.

# Actor input Schema

## `rows` (type: `array`):

Each object: rowId (opaque string, 1–128 chars), packageNdc (string), format (ndc10 or ndc11). NDC10 must be hyphenated. NDC11 may be 11 digits or 5-4-2; ambiguous inverse layouts are uncharged. No URLs or patient details.

## Actor input object example

```json
{
  "rows": [
    {
      "rowId": "catalog-listed",
      "packageNdc": "0228-2551-06",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-related-only",
      "packageNdc": "0781-9401-78",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ambiguous",
      "packageNdc": "0228255106",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-invalid",
      "packageNdc": "not-an-ndc",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ndc11",
      "packageNdc": "76045021010",
      "format": "ndc11"
    },
    {
      "rowId": "catalog-duplicate",
      "packageNdc": "0228-2551-06",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ndc11-ambiguous",
      "packageNdc": "00228255106",
      "format": "ndc11"
    }
  ]
}
```

# Actor output Schema

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

No description

## `csv` (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 = {
    "rows": [
        {
            "rowId": "catalog-listed",
            "packageNdc": "0228-2551-06",
            "format": "ndc10"
        },
        {
            "rowId": "catalog-related-only",
            "packageNdc": "0781-9401-78",
            "format": "ndc10"
        },
        {
            "rowId": "catalog-ambiguous",
            "packageNdc": "0228255106",
            "format": "ndc10"
        },
        {
            "rowId": "catalog-invalid",
            "packageNdc": "not-an-ndc",
            "format": "ndc10"
        },
        {
            "rowId": "catalog-ndc11",
            "packageNdc": "76045021010",
            "format": "ndc11"
        },
        {
            "rowId": "catalog-duplicate",
            "packageNdc": "0228-2551-06",
            "format": "ndc10"
        },
        {
            "rowId": "catalog-ndc11-ambiguous",
            "packageNdc": "00228255106",
            "format": "ndc11"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("technicaldost/fda-shortage-catalog-reconciler").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 = { "rows": [
        {
            "rowId": "catalog-listed",
            "packageNdc": "0228-2551-06",
            "format": "ndc10",
        },
        {
            "rowId": "catalog-related-only",
            "packageNdc": "0781-9401-78",
            "format": "ndc10",
        },
        {
            "rowId": "catalog-ambiguous",
            "packageNdc": "0228255106",
            "format": "ndc10",
        },
        {
            "rowId": "catalog-invalid",
            "packageNdc": "not-an-ndc",
            "format": "ndc10",
        },
        {
            "rowId": "catalog-ndc11",
            "packageNdc": "76045021010",
            "format": "ndc11",
        },
        {
            "rowId": "catalog-duplicate",
            "packageNdc": "0228-2551-06",
            "format": "ndc10",
        },
        {
            "rowId": "catalog-ndc11-ambiguous",
            "packageNdc": "00228255106",
            "format": "ndc11",
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("technicaldost/fda-shortage-catalog-reconciler").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 '{
  "rows": [
    {
      "rowId": "catalog-listed",
      "packageNdc": "0228-2551-06",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-related-only",
      "packageNdc": "0781-9401-78",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ambiguous",
      "packageNdc": "0228255106",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-invalid",
      "packageNdc": "not-an-ndc",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ndc11",
      "packageNdc": "76045021010",
      "format": "ndc11"
    },
    {
      "rowId": "catalog-duplicate",
      "packageNdc": "0228-2551-06",
      "format": "ndc10"
    },
    {
      "rowId": "catalog-ndc11-ambiguous",
      "packageNdc": "00228255106",
      "format": "ndc11"
    }
  ]
}' |
apify call technicaldost/fda-shortage-catalog-reconciler --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,technicaldost/fda-shortage-catalog-reconciler"
        }
    }
}
```

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/8ecCedXUeM9cX0E3i/builds/hl8yrl3haXC8N3EoT/openapi.json
