{
  "name": "VisionOne Market Intel — SharePoint Doc Watcher",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            { "field": "minutes", "minutesInterval": 15 }
          ]
        }
      },
      "id": "trigger-poll",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "getAll",
        "siteId": "={{ $env.VO_SHAREPOINT_SITE_ID }}",
        "driveId": "={{ $env.VO_SHAREPOINT_DRIVE_ID }}",
        "folderPath": "={{ $env.VO_SHAREPOINT_WATCH_FOLDER }}",
        "returnAll": false,
        "limit": 50,
        "filters": {
          "lastModifiedDateTime": "={{ $now.minus({minutes: 20}).toISO() }}"
        }
      },
      "id": "list-files",
      "name": "List recent SharePoint files",
      "type": "n8n-nodes-base.microsoftSharePoint",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "download",
        "siteId": "={{ $env.VO_SHAREPOINT_SITE_ID }}",
        "fileId": "={{ $json.id }}"
      },
      "id": "download-file",
      "name": "Download file",
      "type": "n8n-nodes-base.microsoftSharePoint",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.VO_MARKETINTEL_BASE_URL }}/api/marketintel-documents/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "x-api-key", "value": "={{ $env.VO_MARKETINTEL_API_KEY }}" },
            { "name": "x-wt-tenant", "value": "={{ $env.VO_MARKETINTEL_TENANT_ID }}" }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            { "name": "file", "value": "={{ $binary.data }}", "parameterType": "formBinaryData", "inputDataFieldName": "data" },
            { "name": "fileName", "value": "={{ $('List recent SharePoint files').item.json.name }}" },
            { "name": "sourceContext", "value": "internal" },
            { "name": "segmentId", "value": "={{ $env.VO_DEFAULT_SEGMENT_ID || '' }}" }
          ]
        }
      },
      "id": "upload-to-marketintel",
      "name": "Upload to Market Intel",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Every 15 minutes": { "main": [[{ "node": "List recent SharePoint files", "type": "main", "index": 0 }]] },
    "List recent SharePoint files": { "main": [[{ "node": "Download file", "type": "main", "index": 0 }]] },
    "Download file": { "main": [[{ "node": "Upload to Market Intel", "type": "main", "index": 0 }]] }
  },
  "pinData": {},
  "settings": { "executionOrder": "v1" },
  "tags": [{ "name": "VisionOne Market Intel" }],
  "meta": {
    "templateNote": "Set env vars VO_SHAREPOINT_SITE_ID, VO_SHAREPOINT_DRIVE_ID, VO_SHAREPOINT_WATCH_FOLDER, VO_MARKETINTEL_BASE_URL, VO_MARKETINTEL_API_KEY, VO_MARKETINTEL_TENANT_ID. Optional: VO_DEFAULT_SEGMENT_ID to auto-scope new uploads to a specific segment."
  }
}
