{
  "id": "2dlTwD1DrcbRqWKx",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "PDF Renewal Invoices for Expiring Domains",
  "tags": [],
  "nodes": [
    {
      "id": "3cb86dab-ce3f-4d55-b745-0807a76d29b3",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -256,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "af583293-d0f7-4658-ab65-038bc26be776",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        416,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "176fd118-203d-4e22-8413-56f6922e2d28",
              "operator": {
                "type": "dateTime",
                "operation": "equals"
              },
              "leftValue": "={{ $json.EXPIRING }}",
              "rightValue": "={{ $now.format('dd/LL/yyyy') }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "cebbaa8e-bce9-4d11-b8c3-426e26ab8b0d",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -256,
        -176
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1e334d2f-ef35-4f7c-9583-ec51f85eb60e",
      "name": "Create PDF Invoice",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        784,
        -80
      ],
      "parameters": {
        "url": "https://api.craftmypdf.com/v1/create",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n      \"template_id\": \"xxxxxxxx\",\n      \"output_file\": \"output.pdf\",\n  \"data\": {\n    \"invoice_number\": \"{{ $json.row_number - 1 }}\",\n    \"items\": [\n        {\n            \"name\": \"Renew domain {{ $json.DOMAIN }}\",\n            \"price\": \"{{ $json.RENEW }}\",\n            \"quantity\": 1,\n            \"total\": \"{{ $json.RENEW }}\"\n        }\n    ],\n    \"grand_total\": \"{{ $json.RENEW }}\"\n}\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c1d8ce55-ea95-4e43-8378-857aa4213a0c",
      "name": "Get PDF Invoice",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1008,
        -80
      ],
      "parameters": {
        "url": "={{ $json.file }}",
        "options": {}
      },
      "typeVersion": 4.4
    },
    {
      "id": "0b5cd530-2ccf-4a82-9a4f-b28ecb922ad7",
      "name": "Update Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1664,
        -80
      ],
      "parameters": {
        "columns": {
          "value": {
            "DOMAIN": "",
            "row_number": "={{ $('Get domains').item.json.row_number }}",
            "INVOICE SENT": "x"
          },
          "schema": [
            {
              "id": "EXPIRING",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "EXPIRING",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DOMAIN",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "DOMAIN",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "RENEW",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "RENEW",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CLIENT EMAIL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "CLIENT EMAIL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "INVOICE SENT",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "INVOICE SENT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "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/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit?usp=drivesdk",
          "cachedResultName": "Expiring domains"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "13f402ba-c17d-44e4-ab35-c8a66ee69e3e",
      "name": "Add next expire date",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1872,
        -80
      ],
      "parameters": {
        "columns": {
          "value": {
            "RENEW": "={{ $('Get domains').item.json.RENEW }}",
            "DOMAIN": "={{ $('Get domains').item.json.DOMAIN }}",
            "EXPIRING": "={{$now.plus({ years: 1 }).format('dd/LL/yyyy')}}",
            "CLIENT EMAIL": "={{ $('Get domains').item.json['CLIENT EMAIL'] }}"
          },
          "schema": [
            {
              "id": "EXPIRING",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "EXPIRING",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DOMAIN",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "DOMAIN",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "RENEW",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "RENEW",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CLIENT EMAIL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "CLIENT EMAIL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "INVOICE SENT",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "INVOICE SENT",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit?usp=drivesdk",
          "cachedResultName": "Expiring domains"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "f6e41c79-35ca-4a48-bfb7-165ebe07d851",
      "name": "Send invoice",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1328,
        -80
      ],
      "parameters": {
        "sendTo": "={{ $('Get domains').item.json['CLIENT EMAIL'] }}",
        "message": "=Hi,\n\nI hope you are doing well.\n\nPlease find attached the invoice for the renewal of your domain {{ $('Get domains').item.json.DOMAIN }}. Kindly review it and let us know if you have any questions.\n\nWe would appreciate your payment within the indicated due date.\n\nThank you for your continued trust and cooperation.\n\nBest regards,\nDavide",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        },
        "subject": "=Invoice {{ $('Get domains').item.json.DOMAIN }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "09374338-857c-4bb8-82fd-cb2d36335520",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -592
      ],
      "parameters": {
        "width": 944,
        "height": 384,
        "content": "## Auto Send PDF Renewal Invoices for Expiring Domains\n\nThis workflow automates the **management of expiring domains** and **invoice generation**.\n\nThe workflow checks whether a domain is expiring on the current date. If so, it automatically generates a PDF invoice using an external API, downloads the invoice, and emails it to the client.\n\nAfter sending the invoice, the workflow updates the Google Sheet to mark the invoice as sent and **adds a new expiration date for the next year**, ensuring continuous tracking of domain renewals.\n\n### How it works\n\nThis workflow checks a Google Sheet for domains expiring today, then automatically generates a PDF renewal invoice through the CraftMyPDF API. It downloads the invoice, emails it to the client via Gmail, marks the invoice as sent, and adds a new expiration date for the next year to keep renewal tracking up to date.\n\n### Setup steps\n\nCreate a Google Sheet with domain renewal data, including expiration date, domain, price, client email, and invoice status. Configure Google Sheets, Gmail, and CraftMyPDF credentials in n8n, add your CraftMyPDF template ID, and ensure the workflow date format matches the sheet format.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9646f9b9-f74e-41de-b94e-2815ea254619",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 352,
        "content": "## STEP 1 - Domains List\n[Clone this Sheet](https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit?usp=sharing)"
      },
      "typeVersion": 1
    },
    {
      "id": "4ef09c88-6f09-42e1-a75a-df6a045544ae",
      "name": "Get domains",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        112,
        0
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "INVOICE SENT"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13ATeYMElPDiapkPvhAL4DPcUtcG5jucx594XR5kJgjY/edit?usp=drivesdk",
          "cachedResultName": "Expiring domains"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "86351fae-60fa-46bf-9b4d-d66266d1b353",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 352,
        "content": "## STEP 2 - Create invoice\nCreate on CraftMyPDF an [invoice like this](https://n3wstorage.b-cdn.net/test/test_invoice.pdf) with all placeholders\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6ec47c18-f12e-4972-9ad2-bb1b5b3e4416",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 352,
        "content": "## STEP 3 - Send invoice\nSend invoice to client with Gmail\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f15f14be-a6b6-4ccd-8d50-51b48901a063",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1616,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 352,
        "content": "## STEP 4 - Calculate next expire date\nCalculate and add a new row with next expire date\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "ffa22472-3716-4f69-ab4a-d1f22a9087de",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Create PDF Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get domains": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send invoice": {
      "main": [
        [
          {
            "node": "Update Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Sheet": {
      "main": [
        [
          {
            "node": "Add next expire date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get PDF Invoice": {
      "main": [
        [
          {
            "node": "Send invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create PDF Invoice": {
      "main": [
        [
          {
            "node": "Get PDF Invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}