{
  "id": "UJPZC5iE3WG9H1xs",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Auto-Generate Business Documents in PDF",
  "tags": [],
  "nodes": [
    {
      "id": "171902dc-bc1e-41a0-bbde-f9ad294a25a8",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -440,
        -60
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "e506b2b6-4948-4fd5-b292-bb60de3584f6",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        80,
        -60
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "4621dd93-5acd-4c52-862d-859973a25cf2",
      "name": "Get employees",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -160,
        -60
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "DONE"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg/edit?usp=drivesdk",
          "cachedResultName": " Job Application\tPDFs"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "6a0caf1d-301e-49fb-8f7a-d902a80b8476",
      "name": "Create agreement",
      "type": "n8n-nodes-craftmypdf.craftMyPdf",
      "position": [
        340,
        -40
      ],
      "parameters": {
        "data": "={\n    \"first_name\": \"{{ $json[\"FIRST NAME\"] }}\",\n    \"last_name\": \"{{ $json[\"LAST NAME\"] }}\",\n    \"address_street1\": \"{{ $json.ADDRESS }}\",\n    \"address_street2\": \"\",\n    \"address_city\": \"{{ $json.CITY }}\",\n    \"address_state\": \"{{ $json.STATE }}\",\n    \"address_postal\": \"{{ $json[\"ZIP CODE\"] }}\",\n    \"address_country\": \"{{ $json.COUNTRY }}\",\n    \"email\": \"{{ $json.EMAIL }}\",\n    \"phone_number\": \"{{ $json.PHONE }}\",\n    \"position\": \"{{ $json.POSITION }}\"\n}",
        "resource": "pdf",
        "templateId": "30c77b239c7aa810"
      },
      "credentials": {
        "craftMyPdfApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "35b1c198-c56c-4826-91aa-664686bf3ca0",
      "name": "Get agreement",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        860,
        -60
      ],
      "parameters": {
        "url": "={{ $('Create agreement').item.json.file }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "1a7ce678-eb84-4213-a0ef-539854353e81",
      "name": "Upload agreement",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        340,
        200
      ],
      "parameters": {
        "name": "={{ $('Get employees').item.json[\"FIRST NAME\"] }}-{{ $('Get employees').item.json[\"LAST NAME\"] }}.pdf",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1dksdhaLr6zt43_cyyLGdHCPsMajAM7FG",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1dksdhaLr6zt43_cyyLGdHCPsMajAM7FG",
          "cachedResultName": "Job Application"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0024b884-2bc4-4c53-8d35-db61bb351880",
      "name": "Update row",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        860,
        260
      ],
      "parameters": {
        "columns": {
          "value": {
            "DONE": "x",
            "row_number": "={{ $('Loop Over Items').item.json.row_number }}"
          },
          "schema": [
            {
              "id": "FIRST NAME",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "FIRST NAME",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "LAST NAME",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "LAST NAME",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ADDRESS",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ADDRESS",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CITY",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "CITY",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "STATE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "STATE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ZIP CODE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ZIP CODE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "COUNTRY",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "COUNTRY",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "EMAIL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "EMAIL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "PHONE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "PHONE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "POSITION",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "POSITION",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DONE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "DONE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg/edit?usp=drivesdk",
          "cachedResultName": " Job Application\tPDFs"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "0c6b6f65-5331-4c80-8ad4-1e3d89361ecd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        -360
      ],
      "parameters": {
        "width": 520,
        "height": 220,
        "content": "## PRELIMINARY STEPS\n\nOnly works with the self-hosted version of n8n\n- Clone this [Sheet](https://docs.google.com/spreadsheets/d/1YQPuoEubRHJepRKdquks69Iqf2XdGVKfpWOdYwk3RMg/edit?usp=sharing)\n- Create an account on [CraftMyPDF](https://app.craftmypdf.com/)\n- Create a new PDF template\n- Get the Template ID and insert it in the \"Create aggreement\" node"
      },
      "typeVersion": 1
    },
    {
      "id": "4cea2139-0fd1-4ec0-a48d-5adfcaad268f",
      "name": "Success?",
      "type": "n8n-nodes-base.if",
      "position": [
        580,
        -40
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "21203490-bc55-4981-95ed-50674887967b",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "success"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0701598a-fdb8-4fd3-8b2d-14487c82bf8c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        -620
      ],
      "parameters": {
        "color": 3,
        "width": 520,
        "height": 240,
        "content": "## Auto-Generate Business Documents in PDF\n \n\nThis workflow allows you to generate contracts in bulk (job proposals, general documents, pay slips, invoices, contracts, etc.) in PDF format, starting from a Google Sheet containing the data to be inserted.\n\nAfter creating a PDF template (using CraftMyPDF), this workflow manages the entire process, from filling out the PDF files, to sending emails with attachments, to archiving them on Google Drive (or an equivalent system), in a fully automated way."
      },
      "typeVersion": 1
    },
    {
      "id": "34ea77ea-cb4f-4227-be35-da9932f72111",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        580,
        260
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "18541572-a7fb-42b9-91ec-1275fd116ac7",
      "name": "Send email with PDF",
      "type": "n8n-nodes-base.gmail",
      "position": [
        340,
        380
      ],
      "parameters": {
        "sendTo": "={{ $('Get employees').item.json.EMAIL }}",
        "message": "=Hi {{ $('Get employees').item.json['FIRST NAME'] }} {{ $('Get employees').item.json['LAST NAME'] }},<br>\nAttached is our job proposal<br><br>\nBest,<br>\n[Company name]",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          },
          "appendAttribution": false
        },
        "subject": "Job offer"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "eb1f9c9b-1b50-485e-ab00-ed35e51a9c97",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Update row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Success?": {
      "main": [
        [
          {
            "node": "Get agreement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update row": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get agreement": {
      "main": [
        [
          {
            "node": "Upload agreement",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send email with PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get employees": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Create agreement",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create agreement": {
      "main": [
        [
          {
            "node": "Success?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload agreement": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send email with PDF": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get employees",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}