# SAM.gov data in JavaScript In JavaScript, a fetch call with an Authorization: Bearer header returns a SAM.gov entity or a page of contract opportunities as JSON. It runs in Node 18+ and on edge runtimes without extra packages. Call the API from your server or a serverless function, never from the browser, so the key stays private. Check r.ok before reading the body.Checked on 2026-11-12.Official source: [open.gsa.gov](https://open.gsa.gov/api/) | Runtime | Node 18+, Deno, Bun, edge | | --- | --- | | Auth | Bearer key | | Pagination | next_cursor | ## Entity by UEI ``` const r = await fetch("https://samgovapi.io/api/v1/entities/ABCDEFGH1234", { headers: { Authorization: `Bearer ${process.env.SAMGOVAPI_API_KEY}` }, }); if (!r.ok) throw new Error(`HTTP ${r.status}`); console.log(await r.json()); ``` ## Opportunity search ``` const r = await fetch("https://samgovapi.io/api/v1/opportunities?q=cybersecurity&active=true", { headers: { Authorization: `Bearer ${process.env.SAMGOVAPI_API_KEY}` }, }); if (!r.ok) throw new Error(`HTTP ${r.status}`); console.log(await r.json()); ``` ## Keep the key server-side Call the API from your server or a serverless function, never from the browser, so the key stays private. ## Paging in JavaScript ``` let cursor = null; do { const url = new URL("https://samgovapi.io/api/v1/opportunities"); url.searchParams.set("q", "cybersecurity"); if (cursor) url.searchParams.set("cursor", cursor); const r = await fetch(url, { headers: { Authorization: `Bearer ${process.env.SAMGOVAPI_API_KEY}` } }); const body = await r.json(); for (const row of body.rows) console.log(row.notice_id, row.title); cursor = body.next_cursor; } while (cursor); ``` ## Errors Check r.ok before reading the body. A 429 response names the limit that was hit and when it resets; back off on the per-minute limit and upgrade or top up for the monthly one. ## Get this as JSON ``` curl "https://samgovapi.io/api/v1/opportunities?q=cybersecurity&active=true" \ -H "Authorization: Bearer sg_YOUR_KEY" ``` MCP tool: `search_opportunities`Keys start free, with no card. [Get a free API key](https://samgovapi.io/sign-up) or read the [docs](https://samgovapi.io/docs). ## Related - [Python](https://samgovapi.io/python) - [Quickstart](https://samgovapi.io/docs/quickstart) - [MCP server](https://samgovapi.io/mcp)Updated 2026-11-12. Sources checked 2026-11-12.Independent. Not affiliated with, endorsed by or sponsored by GSA, SAM.gov or any U.S. government agency. Registering in SAM.gov is free at sam.gov.

---

HTML version: https://samgovapi.io/javascript . Markdown: https://samgovapi.io/javascript.md

Independent. Not affiliated with, endorsed by or sponsored by GSA, SAM.gov or any U.S. government agency. Registering in SAM.gov is free at sam.gov.

Get a free API key: https://samgovapi.io/sign-up?ref=ai-claudebot
