{
  "name": "SAM.gov daily opportunities digest (Skillaisle)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 7
            }
          ]
        }
      },
      "id": "7d1e5a20-0b6c-4b8e-9a51-000000000001",
      "name": "Every day 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c2",
              "name": "naicsPrefixes",
              "value": "",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "state",
              "value": "",
              "type": "string"
            },
            {
              "id": "c4",
              "name": "setAside",
              "value": "",
              "type": "string"
            },
            {
              "id": "c5",
              "name": "postedDate",
              "value": "={{ $now.minus({ days: 1 }).toFormat('MM/dd/yyyy') }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "7d1e5a20-0b6c-4b8e-9a51-000000000002",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "url": "https://api.sam.gov/opportunities/v2/search",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "postedFrom",
              "value": "={{ $json.postedDate }}"
            },
            {
              "name": "postedTo",
              "value": "={{ $json.postedDate }}"
            },
            {
              "name": "ptype",
              "value": "o,k"
            },
            {
              "name": "limit",
              "value": "1000"
            },
            {
              "name": "offset",
              "value": "0"
            }
          ]
        },
        "options": {
          "timeout": 60000
        }
      },
      "id": "7d1e5a20-0b6c-4b8e-9a51-000000000003",
      "name": "Get SAM.gov opportunities",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const cfg = $('Config').first().json;\nconst prefixes = String(cfg.naicsPrefixes || '').split(/[ ,]+/).filter(Boolean);\nconst state = String(cfg.state || '').trim().toUpperCase();\nconst setAside = String(cfg.setAside || '').trim();\nconst data = $input.first().json.opportunitiesData || [];\nconst checklist = [\n  'SAM.gov registration active and UEI ready?',\n  'Small under the size standard for this NAICS code (SBA table)?',\n  'Hold the certification this set-aside requires?',\n  'Enough time before the question and offer deadlines?',\n  'Can perform at this location with the licenses/insurance listed?'\n].join(' | ');\nconst rows = data\n  .filter(o => !prefixes.length || prefixes.some(p => String(o.naicsCode || '').startsWith(p)))\n  .filter(o => !state || ((o.placeOfPerformance || {}).state || {}).code === state)\n  .filter(o => !setAside || o.typeOfSetAside === setAside)\n  .map(o => {\n    const due = o.responseDeadLine ? new Date(o.responseDeadLine) : null;\n    return {\n      title: o.title,\n      solicitation: o.solicitationNumber || '',\n      agency: o.fullParentPathName || '',\n      type: o.type,\n      naics: o.naicsCode || '',\n      set_aside: o.typeOfSetAsideDescription || '',\n      place_state: ((o.placeOfPerformance || {}).state || {}).code || '',\n      posted: o.postedDate,\n      response_deadline: o.responseDeadLine || '',\n      days_left: due && !isNaN(due) ? Math.ceil((due - Date.now()) / 86400000) : '',\n      link: 'https://sam.gov/opp/' + o.noticeId + '/view',\n      bid_no_bid_questions: checklist\n    };\n  })\n  .sort((a, b) => String(a.response_deadline || '9999').localeCompare(String(b.response_deadline || '9999')));\nreturn rows.length ? rows.map(r => ({ json: r })) : [{ json: { title: 'No matching notices for ' + cfg.postedDate } }];"
      },
      "id": "7d1e5a20-0b6c-4b8e-9a51-000000000004",
      "name": "Filter and add checklist",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "operation": "csv",
        "options": {
          "fileName": "={{ 'sam-digest-' + $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') + '.csv' }}"
        }
      },
      "id": "7d1e5a20-0b6c-4b8e-9a51-000000000005",
      "name": "Save as CSV",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        880,
        0
      ]
    }
  ],
  "connections": {
    "Every day 07:00": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "Get SAM.gov opportunities",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get SAM.gov opportunities": {
      "main": [
        [
          {
            "node": "Filter and add checklist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter and add checklist": {
      "main": [
        [
          {
            "node": "Save as CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}