# SAM.gov Contracts Scraper (`magicfingers/sam-gov-scraper`) Actor

Scrape government contract opportunities, entity registrations, and award data from SAM.gov. Search by keyword, NAICS code, set-aside type, agency, date range, and more. Uses the official SAM.gov public API.

- **URL**: https://apify.com/magicfingers/sam-gov-scraper.md
- **Developed by:** [abdulrahman alrashid](https://apify.com/magicfingers) (community)
- **Categories:** Other
- **Features:** Limited permissions
- **Stats:** 44 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## 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 Government Contract Scraper

Scrape government contract opportunities, entity/vendor registrations, and award data from [SAM.gov](https://sam.gov) — the U.S. federal government's official system for award management.

Government contracting is a **$700B+ annual market**. This actor helps small businesses, government contractors, BD professionals, and researchers find relevant federal contract opportunities programmatically.

### What data can you scrape?

#### Contract Opportunities

- Title, solicitation number, notice type
- Agency, sub-agency, office
- Posted date, response deadline, archive date
- Set-aside type (small business, 8(a), HUBZone, SDVOSB, WOSB, etc.)
- NAICS codes, product/service classification codes
- Full description text
- Point of contact (name, email, phone)
- Place of performance (city, state, ZIP)
- Attached documents list
- Direct URL to SAM.gov listing

#### Entity/Vendor Registrations

- Legal business name, DBA name
- UEI (Unique Entity Identifier), CAGE code
- Registration status, dates
- Physical and mailing addresses
- NAICS codes with descriptions
- Business types and SBA certifications
- Points of contact
- Congressional district
- Parent entity information

#### Award Data

- Contract/award number
- Award amount
- Awardee name, UEI, CAGE code
- Period of performance
- Associated solicitation data

### How it works

This actor uses a **dual approach**:

1. **SAM.gov Public API** (primary) — Uses the official `api.sam.gov` endpoints for structured, reliable data access
2. **Web scraping fallback** — Falls back to scraping SAM.gov's internal web APIs when no API key is provided

#### API Key

A SAM.gov API key is **free** and gives you the best results. Entity searches require an API key.

**To get your free API key:**

1. Create an account at [SAM.gov](https://sam.gov)
2. Go to Profile → System Account Management
3. Request a public API key (select "Read Public" permission)
4. Enter the key in the actor's input configuration

Without an API key, the actor will attempt web scraping for opportunity searches, but results may be limited.

### Input examples

#### Search for cybersecurity contracts (small business set-aside)

```json
{
    "scrapeMode": "opportunities",
    "apiKey": "YOUR_SAM_GOV_API_KEY",
    "keyword": "cybersecurity",
    "setAsideType": "SBA",
    "maxResults": 50
}
```

#### Search by NAICS code with date range

```json
{
    "scrapeMode": "opportunities",
    "apiKey": "YOUR_SAM_GOV_API_KEY",
    "naicsCode": "541512",
    "postedFrom": "01/01/2024",
    "postedTo": "12/31/2024",
    "maxResults": 200
}
```

#### Find 8(a) set-aside opportunities from the Department of Defense

```json
{
    "scrapeMode": "opportunities",
    "apiKey": "YOUR_SAM_GOV_API_KEY",
    "setAsideType": "8A",
    "agency": "100006688",
    "maxResults": 100
}
```

#### Search for registered IT vendors in Virginia

```json
{
    "scrapeMode": "entities",
    "apiKey": "YOUR_SAM_GOV_API_KEY",
    "keyword": "information technology",
    "naicsCode": "541512",
    "placeOfPerformanceState": "VA",
    "maxResults": 50
}
```

#### Search for recent contract awards

```json
{
    "scrapeMode": "awards",
    "apiKey": "YOUR_SAM_GOV_API_KEY",
    "keyword": "cloud computing",
    "postedFrom": "01/01/2024",
    "maxResults": 100
}
```

### Output format

Each result is a clean JSON object. Here's an example opportunity:

```json
{
    "dataType": "opportunity",
    "opportunityId": "abc123def456",
    "title": "Enterprise Cybersecurity Support Services",
    "solicitationNumber": "W911NF-24-R-0042",
    "noticeType": "Solicitation",
    "noticeTypeCode": "o",
    "agency": "Department of Defense",
    "agencyCode": "DOD",
    "subAgency": "Department of the Army",
    "subAgencyCode": "ARMY",
    "office": "Army Contracting Command",
    "officeCode": "ACC",
    "postedDate": "2024-03-15",
    "responseDeadline": "2024-04-30T14:00:00-04:00",
    "archiveDate": "2024-05-30",
    "setAsideType": "Total Small Business Set-Aside",
    "setAsideCode": "SBA",
    "naicsCodes": ["541512"],
    "classificationCode": "D306",
    "description": "The Army seeks qualified small businesses to provide...",
    "placeOfPerformance": {
        "city": "Arlington",
        "state": "Virginia",
        "stateCode": "VA",
        "country": "United States",
        "countryCode": "US",
        "zip": "22201"
    },
    "pointsOfContact": [
        {
            "type": "primary",
            "fullName": "John Smith",
            "email": "john.smith@army.mil",
            "phone": "703-555-0100"
        }
    ],
    "award": null,
    "attachments": [],
    "active": true,
    "url": "https://sam.gov/opp/abc123def456",
    "scrapedAt": "2024-03-20T10:30:00.000Z"
}
```

### Set-aside type codes

| Code | Description |
|------|-------------|
| `SBA` | Total Small Business Set-Aside |
| `8A` | 8(a) Set-Aside |
| `8AN` | 8(a) Sole Source |
| `HZC` | HUBZone Set-Aside |
| `HZS` | HUBZone Sole Source |
| `SDVOSBC` | Service-Disabled Veteran-Owned SB Set-Aside |
| `SDVOSBS` | Service-Disabled Veteran-Owned SB Sole Source |
| `WOSB` | Women-Owned Small Business |
| `EDWOSB` | Economically Disadvantaged WOSB |
| `VSA` | Veteran-Owned Small Business Set-Aside |
| `VSB` | Veteran-Owned Small Business Sole Source |

### Common NAICS codes for government contracting

| Code | Industry |
|------|----------|
| `541512` | Computer Systems Design Services |
| `541511` | Custom Computer Programming |
| `541330` | Engineering Services |
| `541611` | Administrative Management Consulting |
| `541519` | Other Computer Related Services |
| `236220` | Commercial Building Construction |
| `561210` | Facilities Support Services |
| `561612` | Security Guards and Patrol Services |
| `541690` | Other Scientific and Technical Consulting |
| `238210` | Electrical Contractors |

### Rate limits and pricing

**SAM.gov API rate limits (daily):**

- Non-federal, no role: 10 requests/day
- Non-federal with role: 1,000 requests/day
- Federal system account: 10,000 requests/day

**Actor pricing:** Pay-Per-Event — $1.50 per 1,000 results ($0.0015 per result)

### Legal

All data scraped by this actor is **100% public government data** published on SAM.gov by the U.S. General Services Administration (GSA). SAM.gov provides a public API specifically for programmatic access to this data. There are no legal restrictions on accessing or redistributing this public government information.

### Support

- SAM.gov API documentation: https://open.gsa.gov/api/opportunities-api/
- SAM.gov entity API: https://open.gsa.gov/api/entity-api/
- Get your free API key: https://sam.gov/content/entity-information

# Actor input Schema

## `scrapeMode` (type: `string`):

Choose what type of data to scrape from SAM.gov.

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

Your SAM.gov public API key. Get one free at https://sam.gov/content/entity-information. Required for entity searches; optional for opportunities (falls back to web scraping).

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

Search term to find in opportunity titles, descriptions, or entity names. Examples: 'cybersecurity', 'construction services', 'IT support'.

## `solicitationNumber` (type: `string`):

Specific solicitation number to search for. Example: 'W911NF-23-R-0001'.

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

North American Industry Classification System code to filter by. Examples: '541512' (Computer Systems Design), '236220' (Commercial Building Construction), '541330' (Engineering Services).

## `setAsideType` (type: `string`):

Filter by small business set-aside category.

## `noticeType` (type: `string`):

Filter by type of notice (opportunities mode only).

## `postedFrom` (type: `string`):

Start of posting date range. Format: MM/DD/YYYY. Example: '01/01/2024'.

## `postedTo` (type: `string`):

End of posting date range. Format: MM/DD/YYYY. Example: '12/31/2024'.

## `responseDeadlineFrom` (type: `string`):

Filter opportunities with response deadline after this date. Format: MM/DD/YYYY.

## `responseDeadlineTo` (type: `string`):

Filter opportunities with response deadline before this date. Format: MM/DD/YYYY.

## `agency` (type: `string`):

Filter by federal agency. Use the agency's organization ID or AAC code. Example: '100006688' (Department of Defense).

## `placeOfPerformanceState` (type: `string`):

Two-letter state code for place of performance. Example: 'VA' for Virginia.

## `placeOfPerformanceZip` (type: `string`):

ZIP code for place of performance filtering.

## `classificationCode` (type: `string`):

Filter by product/service classification code. Example: 'D306' (IT and Telecom Systems Development).

## `entityRegistrationStatus` (type: `string`):

Filter entity registrations by status (entities mode only).

## `entityBusinessType` (type: `string`):

Filter entities by business type code (entities mode only). Examples: '2X' (For-Profit), '23' (Minority Owned), 'A2' (Woman Owned).

## `maxResults` (type: `integer`):

Maximum number of results to return. Set to 0 for unlimited. The scraper handles pagination automatically.

## `proxyConfiguration` (type: `object`):

Proxy settings for web scraping fallback. Not needed for API requests.

## Actor input object example

```json
{
  "scrapeMode": "opportunities",
  "keyword": "information technology",
  "setAsideType": "",
  "noticeType": "",
  "entityRegistrationStatus": "A",
  "maxResults": 5,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# 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 = {
    "scrapeMode": "opportunities",
    "keyword": "information technology",
    "maxResults": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("magicfingers/sam-gov-scraper").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 = {
    "scrapeMode": "opportunities",
    "keyword": "information technology",
    "maxResults": 5,
}

# Run the Actor and wait for it to finish
run = client.actor("magicfingers/sam-gov-scraper").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 '{
  "scrapeMode": "opportunities",
  "keyword": "information technology",
  "maxResults": 5
}' |
apify call magicfingers/sam-gov-scraper --silent --output-dataset

```

## MCP server setup

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

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/roR6v71dLchnLmrc2/builds/Tjf07aoV4bT8cEKGB/openapi.json
