`javascript
// Open browser console (F12) and run:
localStorage.setItem('samgov_api_key', 'YOUR_API_KEY_HERE');
`---
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx---
`javascript
// In browser console or JavaScript:
localStorage.setItem('samgov_api_key', 'your-api-key-here');
`.env file in project root:
`env
SAM_GOV_API_KEY=your-api-key-here
``javascript
// Will be created below
const samApi = new SAMGovAPIIntegration();
samApi.setApiKey('your-api-key-here');
`---
---
`javascript
// Initialize with API key
const samApi = new SAMGovAPIIntegration('your-api-key');// Search opportunities const opportunities = await samApi.searchOpportunities({ limit: 10, naicsCode: '541511' // Custom Computer Programming Services });
// Search contracts
const contracts = await samApi.searchContracts({
limit: 10,
minAmount: 10000
});
`
---
`javascript
async function testSAMGovAPI() {
const samApi = new SAMGovAPIIntegration();
// Check if key is set
if (!samApi.apiKey) {
console.error('❌ No API key found');
return;
}
try {
// Try a simple search
const results = await samApi.searchOpportunities({ limit: 1 });
} catch (error) {
console.error('❌ API Error:', error);
}
}// Run test
testSAMGovAPI();
`
`json
{
"opportunitiesData": [{
"noticeId": "abc123",
"title": "IT Services Contract",
"department": "Department of Defense",
"postedDate": "2025-01-15",
"responseDeadline": "2025-02-15"
}],
"totalRecords": 1234
}
`---
`javascript
localStorage.setItem('samgov_api_key', 'YOUR_KEY');
`Solution: Double-check your key from SAM.gov email
Solutions:
Solution: Adjust search parameters
---
The integration includes automatic caching:
`javascript
// Results cached for 1 hour
cache = {
opportunities: [],
contracts: [],
lastUpdate: timestamp
}
// Check cache first
if (cacheValid && cacheAge < 3600) {
return cachedResults;
}
`
Benefits:
---
`
GET https://api.sam.gov/prod/opportunities/v2/search
`
Use For: Contract opportunities, RFPs, solicitations`
GET https://api.sam.gov/prod/federalcontractdata/v1/search
`
Use For: Awarded contracts, spending data`
GET https://api.sam.gov/prod/entity-information/v2/entities
`
Use For: Vendor information, entity details---
---
Add this to any page using SAM.gov:
`html
`
---
- SAM.gov Data Services: https://sam.gov/data-services
---
Before using SAM.gov features:
- [ ] Created SAM.gov account
---
1-Minute Setup:
`bash
`Done! Your SAM.gov integration is now active.
---
Need help? Check console for detailed error messages or visit https://sam.gov/data-services for support.