How to pull open US government bids into JSON or CSV with one API call

2026-11-28来源 dev.toEnglish

US agencies post their bids on hundreds of separate portals. Federal work goes up on SAM.gov. Each state runs its own procurement site. Cities, counties and school districts post on BidNet Direct, Bonfire, PlanetBids, OpenGov, Public Purchase or their own websites. Each portal has its own search form, its own field names and its own way of writing a due date.

If you already know you want this as data, one POST request does it. It returns open bids from 39 sources in a single record shape, as JSON or CSV, and you pay for each bid it returns.

The API call

The work happens in an Apify actor I built, US Government Bids & RFPs. You need an Apify account and its API token, which sits in Apify Console under Settings, then API & Integrations. Put the token in an environment variable named APIFY_TOKEN and run this:

curl -s -X POST "https://api.apify.com/v2/acts/talcoe~us-government-bids-rfps/run-sync-get-dataset-items" \ -H "Authorization: Bearer $APIFY_TOKEN" \ -H "Content-Type: application/json" \ -d '{"keywords": ["hvac"], "states": ["TX", "FL"], "sources": ["sam", "texas", "florida"], "postedWithinDays": 14, "maxResults": 25}' 

The run-sync-get-dataset-items endpoint starts a run, waits for it to finish and sends the results back in the same response. I ran this on November 27. It answered in about 10 seconds with 10 open bids: 4 federal notices from SAM.gov, 5 from the Texas state portal and 1 from Florida's. Here is one of them with the main fields:

{ "id": "texas:405-27R0002094", "source": "texas", "title": "ROSENBERG AO HVAC REPLACEMENT", "agency": "Department Of Public Safety", "agencyType": "state", "state": "TX", "postedDate": "2026-11-25", "dueDate": "2026-12-10T17:00:00", "status": "open", "solicitationNumber": "405-27R0002094", "category": "Energy Computerized Control System (Hvac, Lighting, Utilities, Etc) Installation, Maintenance And Repair Services", "url": "https://www.txsmartbuy.gov/esbd/405-27R0002094" } 

A SAM.gov record carries the same keys and also fills in the NAICS codes, the set aside, the description and links to the attachments. When a portal does not publish a field, that key comes back as null, so your code can read every source the same way. The id stays the same from run to run, which makes it a safe key for skipping bids you have already seen.

Get government bids as a CSV file

Add format=csv to the URL and list the columns you want in fields. The same endpoint then returns a CSV file:

curl -s -X POST "https://api.apify.com/v2/acts/talcoe~us-government-bids-rfps/run-sync-get-dataset-items?format=csv&fields=title,agency,state,dueDate,url" \ -H "Authorization: Bearer $APIFY_TOKEN" \ -H "Content-Type: application/json" \ -d '{"keywords": ["hvac"], "states": ["TX", "FL"], "sources": ["sam", "texas", "florida"], "postedWithinDays": 14, "maxResults": 25}' \ -o hvac_bids.csv 

The file opens in Excel or Google Sheets with one row per bid. Mine had the same 10 bids as the JSON call.

The same search in Python

This script asks for janitorial and custodial work in New York and New Jersey across every source, sorts the bids by due date and writes its own CSV:

import csv import os import requests URL = "https://api.apify.com/v2/acts/talcoe~us-government-bids-rfps/run-sync-get-dataset-items" query = { "keywords": ["janitorial", "custodial"], "states": ["NY", "NJ"], "postedWithinDays": 14, "maxResults": 100, } resp = requests.post(URL, json=query, headers={"Authorization": f"Bearer {os.environ['APIFY_TOKEN']}"}, timeout=600) resp.raise_for_status() bids = sorted(resp.json(), key=lambda b: b.get("dueDate") or "") with open("bids.csv", "w", newline="", encoding="utf-8") as f: w = csv.writer(f) w.writerow(["due", "state", "agency", "title", "url"]) for b in bids: w.writerow([(b.get("dueDate") or "")[:10], b.get("state"), b.get("agency"), b.get("title"), b.get("url")]) print(f"{len(bids)} bids saved to bids.csv") 

My run took 83 seconds and printed 16 bids saved to bids.csv. BidNet Direct found most of them. The rest came from SAM.gov, the New York State Contract Reporter and an OpenGov portal. A sync call waits up to 300 seconds. A search with a broad keyword across many states can run longer than that, so for big searches start the run with POST /v2/acts/talcoe~us-government-bids-rfps/runs and read the dataset when it finishes.

Choosing sources and states

Leave sources out and the actor reads all 39. That is the right default for a real search, and it is also the slowest option, which is why the first two examples name three sources.

The federal source is sam, which reads every active contract opportunity on SAM.gov. Twenty nine state portals sit next to it, from Texas ESBD and MyFloridaMarketPlace to Virginia eVA, Cal eProcure and the New York State Contract Reporter. A state portal only runs when states is empty or includes that state.

Local agencies come from the multi agency platforms. BidNet Direct lists state and local bids in all 50 states. For the other platforms the actor ships with its own lists of agency portals. Bonfire has 398 of them and PlanetBids has 323, most of those in California. Public Purchase adds 861 agency pages. CivicPlus covers 148 city and county websites. OpenGov adds more than 500 portals. The states filter decides which of those get read, so a two state search stays quick.

keywords matches the title, the description and the category, and one matching keyword is enough. postedWithinDays keeps a run to fresh postings. maxResults ends the run at that number of bids, and since you pay per bid it also caps the bill.

A daily feed of only new bids

Turn on onlyNew and give the search a monitorName:

{ "keywords": ["roofing"], "states": ["TX"], "onlyNew": true, "monitorName": "roofing-texas", "maxResults": 200 } 

Each run now returns only the bids this monitor has not delivered before, and you never pay twice for the same bid. I ran this input twice in a row. The first run read every source for Texas in about nine minutes and returned 78 open roofing bids, 72 of them from BidNet Direct. The second run returned none, because nothing new had been posted in between. The list of delivered bids lives in a key value store in your own Apify account for 180 days.

To make it a morning feed, save the input as a task in Apify Console, add a schedule with the cron expression 0 7 * * * and attach an integration for Slack, email, Google Sheets or a webhook. The new roofing bids in Texas then show up where your team already works, every morning, with no script of your own to keep alive.

What it costs

A bid costs $0.006, and each run adds $0.005 when it starts. The HVAC call above returned 10 bids, so it cost $0.065. A daily monitor that finds 40 new bids a morning comes to about $0.25 a day, a little over $7 for a 30 day month. Bids that onlyNew skips are never billed.

Instant search for apps and agents

A run takes from a few seconds to a few minutes, depending on the sources. When an app or a chat agent needs an answer inside one request, use the second actor, Government Bids Search API. It serves a nightly index of the same sources over plain GET requests:

curl -s -H "Authorization: Bearer $APIFY_TOKEN" \ "https://talcoe--government-bids-search-api.apify.actor/search?q=hvac&state=TX&limit=3" 

On November 27 the index held 17,460 open bids, and this query matched 19 of them. A bid returned this way costs $0.008. The index drops a bid once its due date has passed.

Use it from Claude or Cursor

The actor also works as an MCP tool. To add it to Claude Code, run this command.

claude mcp add --transport http us-government-bids "https://mcp.apify.com/?tools=talcoe/us-government-bids-rfps" --header "Authorization: Bearer $APIFY_TOKEN" 

Then ask for something like "open janitorial bids in New Jersey due in the next two weeks" and the agent writes the input for you. The server is in the official MCP Registry as io.github.musama000/us-government-bids, together with federal awards and SBIR awards.

When you want the bids without code

I also run a daily email built on the same data, Talcoe Bid Alerts. You pick trades and states, and the new bids arrive each morning. It costs $49 a month after a 14 day trial that needs no card. There is also a public page for each trade and state that updates every day, such as open HVAC bids in Texas.

I built the actors and the email service described here, and AI helped me write this post.

原文:https://www.a8q9.cn/en/article/how-to-pull-open-us-government-bids-into-json-or-csv-with-one-api-call-3e8926.html

相关文章