Export opportunities from GovDash
This is an outbound sync: GovDash is the source, and your reporting system or CRM is the destination. The example exports changed opportunities as JSON Lines, one record per line, ready for your destination's importer. It pages through results and handles rate limits. For the reverse direction, see Import people into GovDash.
Steps
- Call
GET /v1/opportunitieswithupdated_sinceset to your last successful checkpoint. - Read the opportunity in each edge's
nodeand upsert it in the destination usingidas the unique key. - If
pageInfo.hasNextPageistrue, call again withcursorset topageInfo.endCursor. - If you get
429, waitretry-afterseconds and repeat the same request.
Code
Run the TypeScript sample with npx tsx list-opportunities.ts on Node.js 20 or later. The Python sample needs requests, which you install with pip install requests.
curl --get "$GOVDASH_API_URL/v1/opportunities" \
--data-urlencode "updated_since=2026-10-01T00:00:00Z" \
-H "Authorization: Bearer $GOVDASH_API_KEY" \
-H "govdash-version: $GOVDASH_API_VERSION"const apiVersion = process.env.GOVDASH_API_VERSION
if (!apiVersion) throw new Error("Set GOVDASH_API_VERSION")
const baseUrl = process.env.GOVDASH_API_URL
const apiKey = process.env.GOVDASH_API_KEY
if (!baseUrl || !apiKey)
throw new Error("Set GOVDASH_API_URL and GOVDASH_API_KEY")
const headers = {
Authorization: `Bearer ${apiKey}`,
"govdash-version": apiVersion,
}
type Opportunity = {
id: string
title: string
phase: { id: string; name: string }
updated_at: string
}
type Page<T> = {
edges: { node: T; cursor: string }[]
pageInfo: { hasNextPage: boolean; endCursor: string | null }
}
async function get<T>(path: string, query: URLSearchParams): Promise<T> {
for (let attempt = 1; ; attempt++) {
const response = await fetch(`${baseUrl}${path}?${query}`, {
headers,
})
if (response.status === 429 && attempt < 5) {
const seconds = Number(response.headers.get("retry-after") ?? "1")
await new Promise((r) =>
setTimeout(r, seconds * 1000 * 2 ** (attempt - 1)),
)
continue
}
const body = await response.json()
if (!response.ok) {
throw new Error(
`${response.status} ${body.error.code}: ${body.error.message}`,
)
}
return body as T
}
}
async function* listOpportunities(updatedSince: string) {
const query = new URLSearchParams({ updated_since: updatedSince })
while (true) {
const page = await get<Page<Opportunity>>("/v1/opportunities", query)
for (const edge of page.edges) {
yield edge.node
}
if (!page.pageInfo.hasNextPage || page.pageInfo.endCursor === null) return
query.set("cursor", page.pageInfo.endCursor)
}
}
for await (const opportunity of listOpportunities("2026-10-01T00:00:00Z")) {
console.log(JSON.stringify(opportunity))
}import os
import time
import json
import requests
BASE_URL = os.environ["GOVDASH_API_URL"]
session = requests.Session()
session.headers["Authorization"] = "Bearer " + os.environ["GOVDASH_API_KEY"]
session.headers["govdash-version"] = os.environ["GOVDASH_API_VERSION"]
def get(path, params):
for attempt in range(1, 6):
response = session.get(BASE_URL + path, params=params)
if response.status_code == 429 and attempt < 5:
time.sleep(float(response.headers.get("retry-after", "1")) * 2 ** (attempt - 1))
continue
body = response.json()
if not response.ok:
raise RuntimeError(f"{response.status_code} {body['error']['code']}: {body['error']['message']}")
return body
def list_opportunities(updated_after):
params = {"updated_since": updated_after}
while True:
page = get("/v1/opportunities", params)
for edge in page["edges"]:
yield edge["node"]
if not page["pageInfo"]["hasNextPage"]:
return
params["cursor"] = page["pageInfo"]["endCursor"]
for opportunity in list_opportunities("2026-10-01T00:00:00Z"):
print(json.dumps(opportunity))Deliver the export
Redirect the sample's output to opportunities.ndjson, then load that file with your reporting system's JSON Lines importer. Use id to update existing rows rather than appending duplicates. Replace the printing step with your destination's upsert API when you automate the sync.
The example's timestamp is illustrative. For scheduled runs, save a checkpoint only after the destination accepts every page, and overlap successive runs as described in Sync incrementally. Periodically reconcile a full export if your destination must reflect deletions.
Notes
- With curl, add
--data-urlencode "cursor=<pageInfo.endCursor>"for the next page. - The list leaves out sub-team opportunities and opportunities above your token's classification ceiling.
- List responses never include
custom_fieldsormembers. See Read custom fields.