{
  "id": "3VZQnUWjiVBTZfmP",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Kindle -> Drive upload",
  "tags": [],
  "nodes": [
    {
      "id": "b7a9b0e3-bb4a-4f19-8c25-db1980c8d783",
      "name": "DeepSeek Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "position": [
        336,
        272
      ],
      "parameters": {
        "model": "deepseek-reasoner",
        "options": {}
      },
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e347e4b8-b8fc-4676-b1db-476b3d0c67c6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 416,
        "height": 480,
        "content": "## Step #1: Emails\n\n1. Configure your Amazon Kindle (in the settings of the device itself) to send exports to your gmail address.\n2. Now, configure your gmail node to react to specific emails from a specific amazon address."
      },
      "typeVersion": 1
    },
    {
      "id": "b3c9d3ab-bf67-456d-afe2-2112433f6ec9",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        -864
      ],
      "parameters": {
        "color": 3,
        "width": 2000,
        "height": 512,
        "content": "## Kindle Note Export Automation: PDF Retrieval\n\n### The Challenge\n\nKindle devices that support handwritten notes, such as the Kindle Scribe, offer an option to export notes (notebooks) as PDF files. However, Amazon does not provide a centralized repository or account access for retrieving these past exports; each note export must be requested manually on the device.\n\n### The Export Process Flaw\n\nWhen an export is requested, an email is delivered containing a unique, temporary URL for downloading the PDF file; the file is not attached directly. This manual, multi-step process represents a constraint on user data access and a suboptimal user experience.\n\n### The Automated Solution\n\nThis n8n workflow resolves this limitation by automating the PDF retrieval and storage process. The workflow is designed to:\n\n1. Monitor Inbox: Capture the specific export notification email.\n\n2. Extract URL: Employ an LLM service (like DeepSeek) to reliably parse the email content and extract the unique PDF download URL.\n\n3. Download & Upload: Execute an HTTP request to download the PDF content and automatically upload the file to a configured Google Drive account for reliable backup and future access."
      },
      "typeVersion": 1
    },
    {
      "id": "005f2d08-896b-4eea-b4b8-56773f1fc10f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 480,
        "content": "## Step #2: Convert to HTML\n\n1. Convert the incoming email to HTML to simplify the URL extraction"
      },
      "typeVersion": 1
    },
    {
      "id": "24b03c4b-e7c6-4b61-957d-404322b29bd5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 704,
        "content": "## Step #3: Extract the URL using DeepSeek\n\n1. Instruct the LLM to find that dynamic URL; in theory, you could do that with regex but I am not good at it plus I wanted to test out DeepSeek.\n2. The agent will find that URL and return it for you to use for downloads."
      },
      "typeVersion": 1
    },
    {
      "id": "370bdefe-ecd9-41c9-a457-1706e46a7b6e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 704,
        "content": "## Step #4: Make a request to download those notes\n\n1. Use your extracted URL to grab the .pdf file."
      },
      "typeVersion": 1
    },
    {
      "id": "8007b8d1-8b98-498b-91b4-44c3f06f275c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 704,
        "content": "## Step #5: Upload the .pdf to my GDrive folder for notes\n\n1. Upload the .pdf to my GDrive folder for Kindle Notes.\n2. Inform me by email when the workflow succeeded (last step should only work if every prior action succeeded)."
      },
      "typeVersion": 1
    },
    {
      "id": "6a6fbcaf-4c30-4ae1-894d-2dad3c4b03a9",
      "name": "AI Agent - Link Extraction",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        272,
        0
      ],
      "parameters": {
        "text": "=# role\nact as Frontend Engineer\n\n# task\nfind a URL hiiden in the tag following tag : <span class=\"rio-text rio-text-31\"><a href=\"\n\n# example url\n\"https://www.amazon.com/gp/f.html?C=1MUYIMQ9UFSTL&M=urn:rtn:msg:20250504201451a830d3e5b59a4d1b9d161745fa70p0na&R=7RQXMEKAT28G&T=C&U=https%3A%2F%2Fkindle-content-requests-prod.s3.amazonaws.com%2Fb9a039e0-ec0a-49cb-b89e-6eb8c595351f%2F4.05.25%2520Sunday-2025-05-04-22-13.pdf%3Fresponse-cache-control%3Dno-store%26X-Amz-Algorithm%3DAWS4-HMAC-SHA256%26X-Amz-Date%3D20250504T201443Z%26X-Amz-SignedHeaders%3Dhost%26X-Amz-Credential%3D<redacted-credential>%252F20250504%252Fus-east-1%252Fs3%252Faws4_request%26X-Amz-Expires%3D604800%26X-Amz-Signature%3Db7f25bff8a3d13ede3de43799a5b9a0ff4ae456d174fd50ab38f5513ef9fe26d&H=RQIQEL9ZGIWOUS0YWBKCYACGIWSA\"\n\n# html payload with a hidden link in it\n{{ $json.table }}\n\n# rules \n1. don't make anything up\n2. return only a URL with no formatting, nothing else\n\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "972b53cc-040f-4604-afb8-c2bdd395e938",
      "name": "File upload - Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        960,
        0
      ],
      "parameters": {
        "name": "={{ $('Email ingestion: Gmail trigger').item.json.headers.subject }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1BSU71zLvt-uxi7cE-tcf00fVCIpEUiwA",
          "cachedResultUrl": "https://drive.google.com/drive/folders/XXXXXXXXXXXXXXXXXXXXXXXXXXX",
          "cachedResultName": "Kindle Notes"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7a4ef25d-0853-4fd2-afd1-2b940ca2e517",
      "name": "Success notification - Email",
      "type": "n8n-nodes-base.gmail",
      "onError": "continueRegularOutput",
      "position": [
        1200,
        0
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=KINDLE NOTE SUCCESSFULLY UPLOADED:\n\n{{ $json.name }}",
        "options": {},
        "subject": "KINDLE NOTE SUCCESSFULLY UPLOADED"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "c65a26c5-8a73-4c4d-b242-b22cea9e882f",
      "name": "PDF retrieval - HTTP request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        672,
        0
      ],
      "parameters": {
        "url": "={{ $json.output }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "d64c5a49-cf78-4e56-96ae-448a05da2cec",
      "name": "Link extraction: HTML parser",
      "type": "n8n-nodes-base.html",
      "position": [
        -32,
        0
      ],
      "parameters": {
        "options": {},
        "operation": "convertToHtmlTable"
      },
      "typeVersion": 1.2
    },
    {
      "id": "c547b8c4-d321-49e0-a823-03108a12c7ac",
      "name": "Email ingestion: Gmail trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -336,
        0
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": "from:(amazon.com) subject:(You sent a file)",
          "includeSpamTrash": true
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "cfa64a2e-d401-416e-b7dd-4761f0d30d57",
  "connections": {
    "DeepSeek Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Link Extraction",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Link Extraction": {
      "main": [
        [
          {
            "node": "PDF retrieval - HTTP request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File upload - Google Drive": {
      "main": [
        [
          {
            "node": "Success notification - Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Link extraction: HTML parser": {
      "main": [
        [
          {
            "node": "AI Agent - Link Extraction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDF retrieval - HTTP request": {
      "main": [
        [
          {
            "node": "File upload - Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email ingestion: Gmail trigger": {
      "main": [
        [
          {
            "node": "Link extraction: HTML parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}