{
  "name": "Google Drive new PDF → Issue in Lavisho Trust → email recipient",
  "nodes": [
    {
      "parameters": { "pollTimes": { "item": [{ "mode": "everyMinute" }] }, "triggerOn": "specificFolder", "folderToWatch": { "__rl": true, "mode": "list", "value": "" }, "event": "fileCreated", "options": { "fileType": "application/pdf" } },
      "name": "New PDF in Drive folder", "type": "n8n-nodes-base.googleDriveTrigger", "typeVersion": 1, "position": [0, 0]
    },
    {
      "parameters": { "operation": "download", "fileId": { "__rl": true, "mode": "id", "value": "={{ $json.id }}" }, "options": {} },
      "name": "Download PDF", "type": "n8n-nodes-base.googleDrive", "typeVersion": 3, "position": [220, 0]
    },
    {
      "parameters": { "jsCode": "// Builds the Lavisho Trust issue request. Edit TYPE_CODE and how recipient/fields are derived.\nconst TYPE_CODE = 'CERT';\nconst out = [];\nfor (const item of $input.all()) {\n  const bin = item.binary.data;\n  const buf = await this.helpers.getBinaryDataBuffer(0, 'data');\n  const name = bin.fileName || 'document.pdf';\n  // Example convention: file name \"Jane Doe - jane@example.com.pdf\"\n  const m = name.replace(/\\.pdf$/i, '').match(/^(.*?)\\s*-\\s*([^\\s]+@[^\\s]+)$/);\n  out.push({ json: { type_code: TYPE_CODE, file_base64: buf.toString('base64'), file_name: name, recipient_name: m ? m[1] : null, recipient_email: m ? m[2] : null, external_ref: `gdrive:${$('New PDF in Drive folder').first().json.id}`, source_app: 'n8n', fields: {} } });\n}\nreturn out;" },
      "name": "Build request", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [440, 0]
    },
    {
      "parameters": { "method": "POST", "url": "https://lavishotrust.com/api/public/v1/documents", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "sendHeaders": true, "headerParameters": { "parameters": [{ "name": "Idempotency-Key", "value": "={{ $json.external_ref }}" }] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify($json) }}", "options": {} },
      "name": "Issue in Lavisho Trust", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [660, 0],
      "notes": "Create a Header Auth credential: Name = Authorization, Value = Bearer lt_live_…"
    },
    {
      "parameters": { "method": "POST", "url": "=https://lavishotrust.com/api/public/v1/documents/{{ $json.id }}/email", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {} },
      "name": "Email recipient", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [880, 0]
    }
  ],
  "connections": {
    "New PDF in Drive folder": { "main": [[{ "node": "Download PDF", "type": "main", "index": 0 }]] },
    "Download PDF": { "main": [[{ "node": "Build request", "type": "main", "index": 0 }]] },
    "Build request": { "main": [[{ "node": "Issue in Lavisho Trust", "type": "main", "index": 0 }]] },
    "Issue in Lavisho Trust": { "main": [[{ "node": "Email recipient", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
