{
  "name": "Invoice send workflow",
  "nodes": [
    {
      "parameters": {
        "fromEmail": "info@html2pdf.app",
        "toEmail": "={{ $json.recipient }}",
        "subject": "PDF generated by n8n",
        "html": "=Hello {{ $json.name }},\n\n<br><br>\n\nPlease find your invoice attached.\n\n<br><br>\n\nThank you.",
        "options": {
          "attachments": "data"
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [672, 0],
      "id": "1199895a-0fbb-4977-a40a-a588e18b201e",
      "name": "Send an Email",
      "webhookId": "002b066d-6800-4698-b9da-66a58b9d45f9",
      "credentials": {
        "smtp": {
          "id": "CqZqWsubimF6W4fg",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const clientName = $json.clientName;\nconst clientEmail = $json.clientEmail;\nconst invoiceNumber = $json.invoiceNumber;\nconst total = $json.total;\n\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {\n      font-family: Arial, sans-serif;\n      padding: 40px;\n      color: #333;\n    }\n\n    .invoice {\n      max-width: 700px;\n      margin: 0 auto;\n      border: 1px solid #ddd;\n      padding: 30px;\n    }\n\n    h1 {\n      color: #222;\n    }\n\n    .total {\n      margin-top: 30px;\n      font-size: 24px;\n      font-weight: bold;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"invoice\">\n    <h1>Invoice</h1>\n\n    <p><strong>Invoice Number:</strong> ${invoiceNumber}</p>\n\n    <p><strong>Customer:</strong> ${clientName}</p>\n\n    <div class=\"total\">\n      Total: €${total}\n    </div>\n  </div>\n</body>\n</html>\n`;\n\nreturn {\n    json: {\n      html,\n      recipient: clientEmail,\n      name: clientName\n    }\n  };"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [224, 0],
      "id": "3593f250-8053-4048-9807-6d72c1259315",
      "name": "Generate HTML template"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.html2pdf.app/v1/generate",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "html",
              "value": "={{$json.html}}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [448, 0],
      "id": "a004d4b2-b0fb-432d-be38-2bb639734866",
      "name": "Convert PDF",
      "credentials": {
        "httpHeaderAuth": {
          "id": "3FGBEdk5p5w6FwWP",
          "name": "Header Auth account"
        }
      }
    },
    {
      "parameters": {
        "formTitle": "Generate Invoice",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Client Name",
              "fieldName": "clientName"
            },
            {
              "fieldLabel": "Client Email",
              "fieldType": "email",
              "fieldName": "clientEmail"
            },
            {
              "fieldLabel": "Invoice Number",
              "fieldName": "invoiceNumber"
            },
            {
              "fieldLabel": "Total",
              "fieldName": "total"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [0, 0],
      "id": "8403ae8a-b89b-48d8-85f5-8e0b131baf7e",
      "name": "On form submission",
      "webhookId": "e3f76fe7-e4e2-45fa-9f07-0067962afc34"
    }
  ],
  "pinData": {},
  "connections": {
    "Send an Email": {
      "main": [[]]
    },
    "Generate HTML template": {
      "main": [
        [
          {
            "node": "Convert PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert PDF": {
      "main": [
        [
          {
            "node": "Send an Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Generate HTML template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "7e77daa6-d8fd-4713-95ab-edb5deaad0cf",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "23c98774afcc95dff0404e22154635597468987300c77efdadbab1a0c5fbef2a"
  },
  "id": "8BbwJunJiaAoGw2f",
  "tags": []
}
