# USAspending federal contract and grant awards monitor (`keepable_injera/usaspending-awards-monitor`) Actor

Monitor US federal contract and grant awards by NAICS, PSC, agency, and recipient. Detect new and changed awards with UEI identifiers and source citations.

- **URL**: https://apify.com/keepable_injera/usaspending-awards-monitor.md
- **Developed by:** [Chee Chiaw Lim](https://apify.com/keepable_injera) (community)
- **Categories:** Business, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$2.00 / 1,000 awards

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

## USAspending awards monitor

Collect US federal contract and grant awards from the [USAspending award search API](https://api.usaspending.gov/api/v2/search/spending_by_award/). Filter by NAICS, PSC, awarding agency, recipient keyword, and minimum award amount. Each result includes the source URL, UEI when available, and change metadata.

### Run locally

Use Node.js 20 or later.

```sh
npm install
npm test
npm start
```

The sample input in `storage/key_value_stores/default/INPUT.json` requests up to three contract awards from the last seven days. Local runs contact the real API. Tests stub network calls and use temporary storage.

For an isolated live run, copy the sample input before starting the actor.

```sh
mkdir -p /tmp/usaspending-awards-monitor-live/key_value_stores/default
cp storage/key_value_stores/default/INPUT.json /tmp/usaspending-awards-monitor-live/key_value_stores/default/INPUT.json
CRAWLEE_STORAGE_DIR=/tmp/usaspending-awards-monitor-live APIFY_LOCAL_STORAGE_DIR=/tmp/usaspending-awards-monitor-live node src/main.js
```

Read awards in `datasets/default` and `key_value_stores/default/RUN_SUMMARY.json` under that storage directory.

### Input reference

| Field | Default | Meaning |
| --- | --- | --- |
| `awardTypes` | `["contracts"]` | `contracts`, `grants`, or both as an array. A single group string is also accepted by the runtime. |
| `lookbackDays` | `7` | UTC date window ending today, filtered by `date_signed`. |
| `naicsCodes` | `[]` | Contract industry codes, such as `541512`. |
| `pscCodes` | `[]` | Contract product or service codes, such as `D302`. |
| `agencies` | `[]` | Exact top-tier awarding agency names, such as `Department of Defense`. |
| `recipientKeywords` | `[]` | Recipient search strings passed to `recipient_search_text`. |
| `minAmount` | `0` | Minimum total award amount in USD. |
| `onlyNew` | `true` | Emit new and changed records. Set `false` to include unchanged records. |
| `maxItems` | `100` | Maximum emitted records across groups, from 1 to 10000. |
| `stateStoreName` | `usaspending-awards-monitor-state` | Named key-value store for the award history. |

List filters accept arrays of strings. NAICS and PSC describe contracts. They do not classify grants. An agency or recipient filter can apply to either group. The API combines different filter categories, so narrow combinations may return no awards.

The actor sends contracts `A`, `B`, `C`, `D` and grants `02`, `03`, `04`, `05` in separate requests. Requests use pages of 100, ordered by award amount descending. Groups run in input order. `maxItems` limits emitted records, not the number scanned. An unchanged or excluded page may require further requests.

The actor starts at most one request per second. HTTP 429 and 5xx responses receive up to three retries with exponential backoff and `Retry-After` handling. Other HTTP errors fail the run and appear in `RUN_SUMMARY`.

### Output reference

Each dataset item has these fields.

| Fields | Meaning |
| --- | --- |
| `awardId`, `generatedId`, `awardType` | Source award ID, unique USAspending ID, and requested award group. |
| `recipientName`, `recipientUei` | Recipient name and SAM.gov UEI. |
| `amount` | Total award amount in USD, rather than the latest transaction amount. |
| `awardingAgency`, `awardingSubAgency` | Awarding agency names. |
| `startDate`, `endDate`, `baseObligationDate` | Performance dates and original obligation date. |
| `description` | Award description supplied by the source. |
| `naicsCode`, `naicsDescription`, `pscCode` | Contract classifications. Null for grants. |
| `placeOfPerformanceState`, `lastModified` | Source state code and modification date. |
| `awardUrl`, `source`, `citation`, `checkedAt` | Award link, source attribution, and UTC check time. |
| `changeType`, `changedFields` | `new`, `changed`, or `unchanged`, and changed source field names. |

Unavailable source fields are null. `changedFields` is empty for new and unchanged awards. Volatile check timestamps and change metadata do not cause a record to become changed.

State uses `generatedId` to distinguish awards with similar public IDs. It saves a snapshot only after a successful dataset push. `onlyNew` skips unchanged snapshots. Use a separate `stateStoreName` for independent histories. A crash between a dataset push and state save can repeat that record on the next run.

The date window selects awards by signing date. It is not a complete feed of amendments to older awards. Changes are detected only when an award reappears in the selected window. USAspending reporting delays can also place an award outside a short window.

`RUN_SUMMARY` records run timestamps, fetched, eligible, and pushed counts, whether a charge limit stopped the run, and any run error. The dataset output link and summary link are declared in `.actor/output_schema.json`. The pay-per-event event name is `result`. Every emitted record, including an unchanged record requested with `onlyNew=false`, uses that event.

### Source attribution and licence

Source data comes from [USAspending.gov](https://www.usaspending.gov) and its public API. USAspending permits copying, adapting, and redistributing data for commercial and non-commercial use, subject to its Dun & Bradstreet limitation. See the [USAspending about page](https://www.usaspending.gov/about) and the [D\&B limitation](https://www.fpds.gov/help/DnB.htm). Repository decisions and the terms review are in [TERMS.md](TERMS.md).

Every record carries this citation.

> USAspending.gov, U.S. Department of Treasury, Bureau of the Fiscal Service

`source` and `checkedAt` provide the source link and access time. For published reuse, cite USAspending.gov, U.S. Department of Treasury, Bureau of the Fiscal Service, https://www.usaspending.gov, followed by the access date.

The actor never requests DUNS fields and emits an explicit field allowlist. It drops awards with a missing, invalid, or pre-2022-04-04 `Base Obligation Date`. Filtering by recent signing date alone does not satisfy that exclusion. The original obligation date gate applies independently to contracts and grants.

### Verification status

`npm test` exits successfully. Direct execution of the eight test files reports 20 passing unit cases and three SDK integration cases skipped because `apify` is unavailable. This environment reports only file-level totals for `node --test`, so the skips require checking the individual test output.

This workspace blocks outbound DNS for shell commands. Dependency installation and API requests must succeed before the live acceptance check can pass. Synthetic offline fixtures exercise the API response shape and compliance rules. They are not presented as captured API responses. Replace them with trimmed, DUNS-free live captures when network access is available.

The field selection follows the [official endpoint contract](https://github.com/fedspendingtransparency/usaspending-api/blob/master/usaspending_api/api_contracts/contracts/v2/search/spending_by_award.md). Live curl verification, real-response fixture capture, and a successful live local run remain required before publishing. Nothing in this repository is pushed or deployed by the build workflow.

The attempted isolated live run failed at startup with `ERR_MODULE_NOT_FOUND` for `apify`. Its storage directory contains only the copied input. No live dataset records or `RUN_SUMMARY` were produced. `npm install` failed with `EAI_AGAIN` for `registry.npmjs.org`, and contract and grant curl requests failed to resolve `api.usaspending.gov`.

# Actor input Schema

## `awardTypes` (type: `array`):

Search contracts, grants, or both. Each group uses a separate API request.

## `lookbackDays` (type: `integer`):

UTC date window ending today. Filters by date signed, not last modification.

## `naicsCodes` (type: `array`):

Contract industry codes, such as 541512. Grants do not have NAICS classifications.

## `pscCodes` (type: `array`):

Contract product or service codes, such as D302. Grants do not have PSC classifications.

## `agencies` (type: `array`):

Exact top-tier awarding agency names, such as Department of Defense.

## `recipientKeywords` (type: `array`):

Text passed to the USAspending recipient search filter.

## `minAmount` (type: `number`):

Minimum total award amount in USD. This is not the amount of the latest transaction.

## `onlyNew` (type: `boolean`):

Skip unchanged awards in the named state store. Disable to emit unchanged awards too.

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

Maximum records emitted across all award groups in this run.

## `stateStoreName` (type: `string`):

Named key-value store holding successfully emitted award snapshots. Use a separate store for independent monitoring histories.

## Actor input object example

```json
{
  "awardTypes": [
    "contracts"
  ],
  "lookbackDays": 7,
  "naicsCodes": [],
  "pscCodes": [],
  "agencies": [],
  "recipientKeywords": [],
  "minAmount": 0,
  "onlyNew": true,
  "maxItems": 100,
  "stateStoreName": "usaspending-awards-monitor-state"
}
```

# Actor output Schema

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

No description

## `runSummary` (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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("keepable_injera/usaspending-awards-monitor").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("keepable_injera/usaspending-awards-monitor").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 keepable_injera/usaspending-awards-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,keepable_injera/usaspending-awards-monitor"
        }
    }
}
```

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/tXs8LCYWhXPIHP6rK/builds/aAfjxckswU5VRho57/openapi.json
