{
  "id": "Zm3vlJ68snvoKOBG",
  "name": "google drive workflow",
  "tags": [],
  "nodes": [
    {
      "id": "96c1dd68-0754-4142-b4a3-33da8c7ecbb4",
      "name": "No Operation",
      "type": "n8n-nodes-base.noOp",
      "position": [
        60,
        -180
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1311ef97-df8e-413c-b2a4-744f6d52a464",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        280,
        -280
      ],
      "parameters": {},
      "typeVersion": 2
    },
    {
      "id": "36218a2a-19cb-411b-b16c-abac840c781d",
      "name": "Create Timestamp File",
      "type": "n8n-nodes-base.code",
      "position": [
        1160,
        -280
      ],
      "parameters": {
        "jsCode": "// Get ISO string from DateTime node\nconst dateString = $json['date'] || new Date().toISOString();\n\n// Return in expected format\nreturn [{\n  json: {},\n  binary: {\n    data: {\n      data: Buffer.from(dateString).toString('base64'),\n      mimeType: 'text/plain'\n    }\n  }\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "edc76c05-1f99-4013-b9fe-b13adcac72af",
      "name": "Schedule Trigger1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1480,
        -280
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7127ff0e-88c3-4de3-a20d-9691af5cb97e",
      "name": "Search for Timestamp File1",
      "type": "n8n-nodes-base.googleDrive",
      "onError": "continueRegularOutput",
      "position": [
        -1260,
        -280
      ],
      "parameters": {
        "filter": {},
        "options": {
          "fields": [
            "*"
          ]
        },
        "resource": "fileFolder",
        "returnAll": true,
        "queryString": "=name = 'n8n_last_run.txt' and trashed = false",
        "searchMethod": "query"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "1bec1940-0532-4329-9661-fb2bccf00ccd",
      "name": "Download Timestamp File1",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1040,
        -280
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "93a1e5f1-cfcd-409a-861d-ac2fe26e02fa",
      "name": "Download New Files2",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        60,
        -380
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "97cadaca-a362-401b-9024-f4c982fbdfce",
      "name": "Upload New Timestamp2",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1380,
        -280
      ],
      "parameters": {
        "name": "n8n_last_run.txt",
        "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": "1ycXdgyWRiQ_Ce_IgeZN1au6QKQNYOMJn",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1ycXdgyWRiQ_Ce_IgeZN1au6QKQNYOMJn",
          "cachedResultName": "n8n Workflows"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "1fe60540-aedd-4b20-9ec4-44f63e9c995b",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -160,
        -280
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9f2f6596-c151-4fa1-aadd-ec26345aba4d",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "51894b5f-1a9c-416c-b3ee-49bb20c904f1",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        500,
        -280
      ],
      "parameters": {
        "options": {}
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "3d6cbf9c-da08-42d4-a682-bf0c97700754",
      "name": "Extract Timestamp Text1",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -820,
        -280
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "7004e5b2-1d35-4900-ae9a-90e8d4ce2d49",
      "name": "Edit Fields2",
      "type": "n8n-nodes-base.set",
      "position": [
        -600,
        -280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d6a28651-3a08-4a34-a5a7-e53bb335c83b",
              "name": "searchFromTimestamp",
              "type": "string",
              "value": "={{ $json.data || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "10fae4c7-57ab-44c4-86d1-34ea5fea1316",
      "name": "Search for New Files2",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -380,
        -280
      ],
      "parameters": {
        "filter": {},
        "options": {
          "fields": [
            "*"
          ]
        },
        "resource": "fileFolder",
        "returnAll": true,
        "queryString": "='1ycXdgyWRiQ_Ce_IgeZN1au6QKQNYOMJn' in parents and (createdTime > '{{ $json.searchFromTimestamp }}' OR modifiedTime > '{{ $json.searchFromTimestamp }}') and trashed = false",
        "searchMethod": "query"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "executeOnce": true,
      "typeVersion": 3,
      "alwaysOutputData": true
    },
    {
      "id": "358f5927-e9ce-4935-b9bb-4f34996cb932",
      "name": "Get Current Time1",
      "type": "n8n-nodes-base.dateTime",
      "position": [
        940,
        -280
      ],
      "parameters": {
        "options": {
          "timezone": "UTC",
          "includeInputFields": false
        }
      },
      "typeVersion": 2
    },
    {
      "id": "8f058442-c3e4-47f2-8185-388856bb9338",
      "name": "Delete Old Timestamp File1",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        720,
        -280
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $node[\"Search for Timestamp File1\"].json.id }}"
        },
        "options": {},
        "operation": "deleteFile"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "47c471f5-e804-42f1-a8b5-d35ec2982daa",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1580,
        -520
      ],
      "parameters": {
        "width": 150,
        "height": 180,
        "content": "Workflow Purpose\nThis workflow automatically downloads new or updated files from a Google Drive folder since the last workflow run, using a timestamp file for tracking."
      },
      "typeVersion": 1
    },
    {
      "id": "c8aa3c8a-46ab-449a-936c-93955f6f3083",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -520
      ],
      "parameters": {
        "content": "Setup Required\nYou need to set up your Google Drive credentials in n8n for this workflow to function.\nEdit the nodes marked with \"Google Drive\" to select your credentials and set your target folder ID."
      },
      "typeVersion": 1
    },
    {
      "id": "a5b5c496-231f-44bc-bfb9-7c96b89067cc",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -860,
        -520
      ],
      "parameters": {
        "content": "Timestamp File\nThe workflow looks for a n8n_last_run.txt file in Google Drive to know when it last ran.\nIf the file isn\u2019t found, it defaults to files from the last 24 hours."
      },
      "typeVersion": 1
    },
    {
      "id": "5c5b741d-2237-4228-afc4-a13eea55faf1",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        -600
      ],
      "parameters": {
        "content": "Timestamp Update\nAfter all files are processed, the timestamp file is updated so future runs only process new/changed files."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e46a567b-2ca8-474e-a054-433d282bfce9",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Download New Files2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Delete Old Timestamp File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "Search for New Files2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No Operation": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Time1": {
      "main": [
        [
          {
            "node": "Create Timestamp File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "Search for Timestamp File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download New Files2": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Timestamp File": {
      "main": [
        [
          {
            "node": "Upload New Timestamp2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for New Files2": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Timestamp Text1": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Timestamp File1": {
      "main": [
        [
          {
            "node": "Extract Timestamp Text1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Timestamp File1": {
      "main": [
        [
          {
            "node": "Get Current Time1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for Timestamp File1": {
      "main": [
        [
          {
            "node": "Download Timestamp File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}