Tutorial

Query from JavaScript

Read government notices from server-side JavaScript.

← All tutorials

Before you start

You need active GovBiz API access and a key with the search permission. Create your key first.

Use Node.js 22 or later. Save your key in GOVBIZ_API_KEY. Run this on a server or your local machine.

Each request uses your shared workspace allowance. The examples do not send email or update another service.

Run the example

Save the code in query.mjs. Run it with node query.mjs.

const key = process.env.GOVBIZ_API_KEY;
if (!key) throw new Error("Set GOVBIZ_API_KEY first");
const response = await fetch(
  "https://www.govbiz.ai/api/v2/opportunities/search?naics_code=541512&limit=2",
  { headers: { Authorization: "Bearer " + key },
    signal: AbortSignal.timeout(30000) }
);
if (!response.ok) throw new Error("GovBiz returned " + response.status);
const result = await response.json();
console.table(result.data.results.map(row => ({
  notice_id: row.notice_id,
  title: row.title,
  posted_date: row.posted_date
})));
console.log(result.citations);

Check the result

Read the notice table and citations printed in your terminal.

Live results change. Compare the response shape with our captured sample and check the original notices.

Limits and care

Keep credentials out of shared code, browser bundles, and workbooks you distribute. Excel parameters may be visible to people who can open the workbook.

Check HTTP errors before using results. Retry temporary errors with a delay. Avoid repeated retries for authentication failures.

These examples use explicit filters. They do not make bid decisions or produce proposals.