{
  "name": "Watch Google Drive folder and use iLovePDF Compress Tool to save it in another Google Drive folder",
  "tags": [],
  "nodes": [
    {
      "id": "e6fec128-2f1c-48ff-829f-3e7166fc9976",
      "name": "When clicking \u2018Test workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        608,
        320
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9d4e6c6c-dfcc-4f50-bbd4-01b9988de5f6",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1056,
        608
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "e076cdbf-681d-43fd-b7a2-c69d00f2c6b9",
      "name": "Upload your file to Google Drive",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        608,
        560
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1vtY_ATTQOFggVQ_EnzlrpMcY6XrVpeD0",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4db39f2d-f77c-4a81-b450-e50429803862",
      "name": "Group public key, task and downloaded file data",
      "type": "n8n-nodes-base.merge",
      "position": [
        1280,
        464
      ],
      "parameters": {
        "mode": "combine",
        "options": {
          "includeUnpaired": true
        },
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3
    },
    {
      "id": "6018c0f6-5b17-4823-b70d-69dbd4134e43",
      "name": "Compress your file",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1728,
        464
      ],
      "parameters": {
        "url": "=https://{{ $('Get task from iLoveAPI server').item.json.server }}/v1/process",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"task\": \"{{ $('Get task from iLoveAPI server').item.json.task }}\",\n    \"tool\": \"compress\",\n    \"files\": [\n        {\n            \"server_filename\": \"{{ $json.server_filename }}\",\n            \"filename\": \"{{ $node['Download file'].binary.data.fileName }}\"\n        }\n    ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Send your iLoveAPI public key to their server').item.json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "957761b2-7e1a-4dfb-bb0a-581c8a94408f",
      "name": "Move compressed file to new Google Drive folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2160,
        464
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Upload your file to Google Drive').item.json.id }}"
        },
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1-_vUMwMdKcEo9uLXX9UBCdlS_wHUPzii",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "operation": "move"
      },
      "typeVersion": 3
    },
    {
      "id": "75b524c2-eb15-4c3f-9a37-9a64168a78d9",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -96
      ],
      "parameters": {
        "color": 3,
        "width": 460,
        "height": 976,
        "content": "## Try this iLovePDF Compress Automation!\nThis n8n workflow automates compressing files in Google Drive using iLovePDF. When a file is added to a monitored folder, the workflow compresses it and saves it to another folder, optimizing storage.\n\nThe process includes authenticating with iLoveAPI, initiating the compression task, downloading the compressed file, and moving the original to an archive folder to prevent reprocessing. This setup is ideal for managing large PDFs and improving storage efficiency.\n\n### How it works\n\n- **Google Drive Trigger:** Detects new files in a monitored folder.  \n- **Authentication:** Sends Public Key to iLoveAPI for a Bearer YOUR_TOKEN_HERE  \n- **Start Task:** Starts a compression task with iLoveAPI, returning a Task ID.  \n- **Download/Upload:** Downloads the file and uploads it to iLoveAPI.  \n- **Process:** Compresses the file using iLoveAPI's `/process` endpoint.  \n- **Download Compressed File:** Retrieves the compressed file.  \n- **Save Compressed File:** Uploads it to the destination folder.  \n- **Move Original File:** Moves the original to an archive folder to avoid duplication.\n\n---\n\n### Setup Steps\n\n1. **Credentials:** Set up Google Drive and iLoveAPI in n8n.  \n2. **Public Key:** Paste iLoveAPI Public Key in authentication nodes.  \n3. **Folders:** Set source and destination folders.\n\n---\n\n### Requirements\n\n- Google Drive account/credentials.  \n- iLoveAPI Developer account/API key.  \n- An n8n instance (cloud or self-hosted)."
      },
      "typeVersion": 1
    },
    {
      "id": "0f890a3d-50ff-49c7-8bd7-7fa18c1363d6",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        912
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 172,
        "content": "### Adapt it as you need!\nThis is just an example of using it for you to know how the flow should start to work without issues. After the \"combine\" step, you can change it according your needs but **always maintaining the four main steps of ILoveAPI's request workflow: start, upload, process and download** (e.g., an step for sending an email with the compressed file instead of moving it to another folder)"
      },
      "typeVersion": 1
    },
    {
      "id": "861ae95e-092d-4ca7-ac60-18f72bc9c013",
      "name": "Download compressed file",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1936,
        464
      ],
      "parameters": {
        "url": "=https://{{ $('Get task from iLoveAPI server').item.json.server }}/v1/download/{{ $('Get task from iLoveAPI server').item.json.task }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "={{ $json.download_filename }}"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Send your iLoveAPI public key to their server').item.json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "a98e1f2f-cb8b-480d-a621-5256b7b3bc3c",
      "name": "Send your iLoveAPI public key to their server",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        832,
        368
      ],
      "parameters": {
        "url": "https://api.ilovepdf.com/v1/auth",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "public_key",
              "value": "YOUR_ILOVEAPI_PUBLIC_KEY"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1a895df1-b229-4d0f-b702-f1db3d974a1f",
      "name": "Get task from iLoveAPI server",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1056,
        368
      ],
      "parameters": {
        "url": "https://api.ilovepdf.com/v1/start/compress",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "public_key",
              "value": "YOUR_ILOVEAPI_PUBLIC_KEY"
            },
            {
              "name": "tool",
              "value": "compress"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer  {{ $json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "92b46b65-d33f-485e-a8e2-7aac53dfd788",
      "name": "Upload PDF to iLoveAPI server",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1504,
        464
      ],
      "parameters": {
        "url": "=https://{{ $json.server }}/v1/upload",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "task",
              "value": "={{ $json.task }}"
            },
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Send your iLoveAPI public key to their server').item.json.token }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "98a0918b-55c5-45e0-b6bb-05c19931b983",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 656,
        "content": "## Sets up iLovePDF credentials and gets file from folder"
      },
      "typeVersion": 1
    },
    {
      "id": "2892a063-9e75-4cb1-96da-de862a183dd0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1232,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 848,
        "height": 656,
        "content": "## Unifies data from previous step and does the tool processes."
      },
      "typeVersion": 1
    },
    {
      "id": "51abcbe2-3d64-4452-82ab-dc37e673f27a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2096,
        224
      ],
      "parameters": {
        "color": 7,
        "height": 656,
        "content": "## Upload processed file to drive folder\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "Download file": {
      "main": [
        [
          {
            "node": "Group public key, task and downloaded file data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Compress your file": {
      "main": [
        [
          {
            "node": "Download compressed file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download compressed file": {
      "main": [
        [
          {
            "node": "Move compressed file to new Google Drive folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get task from iLoveAPI server": {
      "main": [
        [
          {
            "node": "Group public key, task and downloaded file data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload PDF to iLoveAPI server": {
      "main": [
        [
          {
            "node": "Compress your file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload your file to Google Drive": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send your iLoveAPI public key to their server",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Send your iLoveAPI public key to their server",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send your iLoveAPI public key to their server": {
      "main": [
        [
          {
            "node": "Get task from iLoveAPI server",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group public key, task and downloaded file data": {
      "main": [
        [
          {
            "node": "Upload PDF to iLoveAPI server",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}