# SAM.gov & Grants.gov Scraper: Federal Contracts & Grants API (`stazis/gov-opportunities-api`) Actor

US government contract opportunities from SAM.gov and federal grants from Grants.gov in one dataset, from their official public APIs. Filter by keyword, agency, NAICS, category and date; only-new mode for daily alerts. SAM.gov needs your own free API key.

- **URL**: https://apify.com/stazis/gov-opportunities-api.md
- **Developed by:** [Stanislav](https://apify.com/stazis) (community)
- **Categories:** Lead generation, Business, Automation
- **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 opportunity 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

## SAM.gov & Grants.gov Scraper: Federal Contracts and Grants

Get **US government contract opportunities from SAM.gov** and **federal grant opportunities from Grants.gov** in one clean dataset, straight from their official public APIs. Filter by keyword, agency, NAICS code, funding category, status and posted date, and schedule it daily in only-new mode to get alerts for fresh RFPs and grants.

- **Who it's for:** government contractors and bid teams, grant writers, nonprofits, consultants and GovCon lead lists.
- **Source:** the Grants.gov Search API (no key needed) and the SAM.gov Get Opportunities Public API (needs your own free SAM.gov API key). No scraping, no login.
- **Alerts:** only-new mode remembers what you already received.
- **Output:** JSON, CSV or Excel; pay per opportunity returned (see the Pricing tab).

### Quick start (one click)

Open the Actor and press **Start**: the form is prefilled with this input.

```json
{
  "keywords": "climate",
  "sources": [
    "grants.gov"
  ],
  "postedWithinDays": 30,
  "stateStoreName": "gov-opps-state",
  "maxItems": 40
}
```

Sample output (one row, more fields in the dataset):

| source | type | id | title | agency |
|---|---|---|---|---|
| grants.gov | grant | L20AS00080 | USDA/USDOI Joint Fire Science Program (JFSP) | Bureau of Land Management |

### Use cases

**Daily grant alerts for a nonprofit.** New and forecasted grants on your topic; only-new mode for a daily schedule.

```json
{"keywords": "climate", "sources": ["grants.gov"], "grantStatuses": ["forecasted", "posted"], "onlyNew": true}
```

**GovCon pipeline by NAICS.** Contract opportunities in your NAICS code from the last 14 days (needs your free SAM.gov key).

```json
{"keywords": "software", "sources": ["sam.gov"], "naicsCode": "541511", "postedWithinDays": 14, "samApiKey": "YOUR_SAM_GOV_KEY"}
```

**Both sources in one feed.** Contracts and grants for one keyword, one schema.

```json
{"keywords": "cybersecurity", "sources": ["sam.gov", "grants.gov"], "samApiKey": "YOUR_SAM_GOV_KEY", "postedWithinDays": 30}
```

**Funding-trend research.** Everything posted in the last 90 days, for analysis.

```json
{"keywords": "artificial intelligence", "sources": ["grants.gov"], "postedWithinDays": 90, "maxItems": 1000}
```

### Features and details of this federal grants API

Get **US federal grant opportunities and government contract notices** in one clean dataset, straight from the official public APIs of **Grants.gov** (no key needed) and **SAM.gov** (your own free API key). Schedule it daily with "only new" mode to get alerts.

#### Why this Actor

- **Official sources only:** Grants.gov Search API and the SAM.gov Get Opportunities Public API. No scraping, no proxies, no login.
- **Grants and contracts in one output format.**
- **Filters:** keywords, agency codes, funding categories, eligibility, status (forecasted, posted, closed, archived), NAICS (SAM.gov), posted within N days.
- **Only new:** remembers what it already returned, so daily runs give you just fresh opportunities.
- **Fast:** about 125 Grants.gov results in ~1 s in our tests.

#### How to use

1. Enter **Keywords** (e.g. `artificial intelligence`, `climate`, `broadband`).
2. Grants.gov works out of the box. For SAM.gov contracts, paste your free personal API key (sam.gov > Account Details > Public API Key).
3. Optionally filter by agency (exact Grants.gov codes such as `NSF`, `HHS-NIH11`, `DOE-GFO`), category, eligibility or NAICS.
4. Click **Start**, then export JSON, CSV or Excel, or use the API, Make, Zapier or n8n.
5. For alerts, add a daily **Schedule** with `onlyNew: true`.

#### Pricing

Pay per result: **$1.00 per 1,000 opportunities** ($0.001 each) plus $0.005 per run start. No subscription.

#### Errors

If one source fails, the run continues and the error is saved in the `ERRORS` key-value record.

### How to use the federal grants API

1. Open the Actor, fill in the input form (or paste the JSON below).
2. Click **Start**. Results land in the dataset as JSON, CSV, Excel or via the Apify API.
3. For alerts or regular refreshes, add an Apify **Schedule**. You can cap spend with "Max charge per run".

### Input example

Real input of cloud run `LuGO1XWkux67LnrCL` (2026-10-22/23):

```json
{
  "keywords": "wildfire",
  "sources": [
    "grants.gov"
  ],
  "grantStatuses": [
    "posted",
    "forecasted"
  ],
  "maxItems": 10
}
```

### Output example

Real rows from that run (10 results, 3.3 s) (long titles shortened in the table):

| id | title | agency | status | posted | closes |
|---|---|---|---|---|---|
| L20AS00080 | USDA/USDOI Joint Fire Science Program (JFSP) | Bureau of Land Management | forecasted | 2020-03-16 | — |
| G27AS00072 | Cooperative Agreement for Affiliated Partner with the Rocky Mountains  | Geological Survey | posted | 2026-10-14 | 2026-11-14 |
| EDA-DISASTER-2023 | FY 2023 Disaster Supplemental | Economic Development Administration | posted | 2023-04-24 | — |
| G27AS00165 | Cooperative Agreement for Affiliated Partner with the Southern Appalac | Geological Survey | posted | 2026-10-01 | 2026-10-30 |
| G27AS00073 | Cooperative Agreement for Affiliated Partner with the Hawaiʻi-Pacific  | Geological Survey | posted | 2026-10-14 | 2026-11-14 |
| EDA-DISASTER-2025 | EDA FY25 Disaster Supplemental | Economic Development Administration | posted | 2025-06-04 | — |

One full record:

```json
{
  "source": "grants.gov",
  "type": "grant",
  "id": "L20AS00080",
  "title": "USDA/USDOI Joint Fire Science Program (JFSP)",
  "agency": "Bureau of Land Management",
  "status": "forecasted",
  "postedDate": "2020-03-16",
  "closeDate": null,
  "assistanceListings": [
    "15.232"
  ],
  "url": "https://www.grants.gov/search-results-detail/325472"
}
```

Dates come as Grants.gov publishes them: some long-running notices keep an old posted date or a far-future close date. Filter with `postedWithinDays` and `grantStatuses`.

### FAQ

#### Do I need a SAM.gov API key?

Only for contract notices. Grants.gov works without a key; for SAM.gov you paste your own free key from your sam.gov account.

#### Why do agency filters need exact codes?

Grants.gov matches sub-agency codes such as HHS-NIH11, not just HHS.

#### Is this affiliated with the government?

No. It only reads public US government APIs.

#### How much does it cost?

$1 per 1,000 opportunities plus $0.005 per run.

#### Are there limits I should know about?

Yes. Results are only as complete and current as the official source. If a source is down, the run logs the error instead of returning made-up data. Report problems in the Issues tab.

### Use it from code, AI agents and automations

The same input as the form above works everywhere. Results are the run's dataset (JSON, CSV, Excel). You need an Apify API token (Console → Settings → API & Integrations).

**Python** (`pip install apify-client`)

```python
from apify_client import ApifyClient

client = ApifyClient("<YOUR_APIFY_TOKEN>")
run = client.actor("stazis/gov-opportunities-api").call(run_input={
  "keywords": "climate",
  "sources": [
    "grants.gov"
  ],
  "postedWithinDays": 30,
  "maxItems": 40
})
for item in client.dataset(run.default_dataset_id).iterate_items():  # apify-client < 3: run["defaultDatasetId"]
    print(item)
```

**JavaScript / TypeScript** (`npm i apify-client`)

```js
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('stazis/gov-opportunities-api').call({
  "keywords": "climate",
  "sources": [
    "grants.gov"
  ],
  "postedWithinDays": 30,
  "maxItems": 40
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
```

**HTTP, one call** (waits for the run, up to 5 minutes, and returns the items)

```bash
curl -X POST "https://api.apify.com/v2/acts/stazis~gov-opportunities-api/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"keywords": "climate", "sources": ["grants.gov"], "postedWithinDays": 30, "maxItems": 40}'
```

**AI agents (MCP).** This Actor runs with limited permissions, so AI agents can use it through the hosted Apify MCP server (Claude, Cursor, VS Code, Codex and other MCP clients). Add this to your MCP client config and sign in with Apify on first use:

```json
{ "mcpServers": { "gov-opportunities-api": { "url": "https://mcp.apify.com?tools=stazis/gov-opportunities-api" } } }
```

Agents without an Apify account can pay per run in USDC through [agi.apify.com](https://agi.apify.com) (x402). Pricing is pay-per-event, so an agent pays only for the results it gets.

**LangChain** (`pip install langchain-apify`, set `APIFY_TOKEN`): `from langchain_apify import ApifyActorsTool` and `tool = ApifyActorsTool("stazis/gov-opportunities-api")` gives your agent this Actor as a tool.

**No-code and scheduling:** use the Apify app in Make, n8n or Zapier ("Run an Actor", then pick `stazis/gov-opportunities-api`), or create a Schedule in Apify Console to run it daily and send results to a webhook, Slack or Google Drive through Apify integrations.

### Other data APIs by stazis

- [Greenhouse, Lever & Ashby Jobs Scraper API](https://apify.com/stazis/ats-jobs-api): Scrape job postings from company career sites via official Greenhouse, Lever, Ashby, Workable, SmartRecruiters and Recruitee job-board APIs.
- [UK Companies House Search API: Bulk Company Data](https://apify.com/stazis/companies-house-api): Search all ~5.
- [SEC EDGAR Filings Scraper API: 8-K, 10-K, Full-Text Search](https://apify.com/stazis/sec-edgar-filings-api): Search SEC EDGAR filings by full text, form type (8-K, 10-K, 10-Q, S-1, Form D), date and state, or list recent filings for any ticker or CIK.
- [Bulk WHOIS & RDAP Domain Lookup API: Expiry, DNS](https://apify.com/stazis/domain-rdap-api): Bulk domain lookup via official RDAP (the WHOIS successor) plus live DNS: registrar, status, created/updated/expiry dates, nameservers, DNSSEC, A/AAAA/MX/NS/TXT records.
- [OpenAlex API: Scholarly Paper Search, Citations, Abstracts](https://apify.com/stazis/openalex-works-api): Search 250M+ scholarly papers from OpenAlex (CC0): title, DOI, year, venue, open-access link, citation count, authors, institutions, topics and abstract.

# Actor input Schema

## `keywords` (type: `string`):

Search words matched against opportunity titles and keywords, e.g. 'climate', 'wildfire', 'cybersecurity'. Leave empty to list everything that matches the other filters.

## `sources` (type: `array`):

Where to search: 'grants.gov' (federal grants, no key needed) and/or 'sam.gov' (federal contract opportunities, needs your own free SAM.gov API key below).

## `samApiKey` (type: `string`):

Your personal SAM.gov public API key (free: sam.gov → Account Details → API Key). Only needed for the 'sam.gov' source; leave empty to skip SAM.gov.

## `naicsCode` (type: `string`):

SAM.gov only: NAICS industry code to filter contract opportunities, e.g. 541512 (computer systems design).

## `grantStatuses` (type: `array`):

Grants.gov statuses to include: forecasted, posted, closed, archived. Default: forecasted and posted (open or upcoming).

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

Grants.gov agency codes, exact match including sub-agency, e.g. NSF, HHS-NIH11, DOE-GFO. Leave empty for all agencies.

## `fundingCategories` (type: `array`):

Grants.gov funding-category codes, e.g. ST (science & technology), ED (education), HL (health), ENV (environment).

## `eligibilities` (type: `array`):

Grants.gov applicant-eligibility codes, e.g. 12 (nonprofits with 501(c)(3)), 20 (private universities), 25 (others).

## `postedWithinDays` (type: `integer`):

Only opportunities posted in the last N days, e.g. 7 for a weekly digest. Leave empty for no date limit.

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

Monitor mode: return only opportunities not returned by earlier runs (remembered in the key-value store below). Use with a schedule.

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

Name of the key-value store that 'Only new' uses. Use a different name per saved search.

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

Maximum results per source per run. Also caps the cost.

## Actor input object example

```json
{
  "keywords": "climate",
  "sources": [
    "grants.gov"
  ],
  "grantStatuses": [
    "forecasted",
    "posted"
  ],
  "postedWithinDays": 30,
  "onlyNew": false,
  "stateStoreName": "gov-opps-state",
  "maxItems": 40
}
```

# Actor output Schema

## `results` (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 = {
    "keywords": "climate",
    "sources": [
        "grants.gov"
    ],
    "postedWithinDays": 30,
    "stateStoreName": "gov-opps-state",
    "maxItems": 40
};

// Run the Actor and wait for it to finish
const run = await client.actor("stazis/gov-opportunities-api").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 = {
    "keywords": "climate",
    "sources": ["grants.gov"],
    "postedWithinDays": 30,
    "stateStoreName": "gov-opps-state",
    "maxItems": 40,
}

# Run the Actor and wait for it to finish
run = client.actor("stazis/gov-opportunities-api").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 '{
  "keywords": "climate",
  "sources": [
    "grants.gov"
  ],
  "postedWithinDays": 30,
  "stateStoreName": "gov-opps-state",
  "maxItems": 40
}' |
apify call stazis/gov-opportunities-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,stazis/gov-opportunities-api"
        }
    }
}
```

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/I7fX4omGo2ui0Kdu7/builds/8xSdpBqcwDTxaXRM4/openapi.json
