{
  "name": "Email Marketing Automation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "webhook",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [240, 300],
      "webhookId": "email-marketing-automation"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.email }}",
              "operation": "notEmpty"
            }
          ]
        }
      },
      "id": "validate-email",
      "name": "Validate Email",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "create",
        "additionalFields": {
          "email": "={{ $json.email }}",
          "firstName": "={{ $json.firstName || '' }}",
          "lastName": "={{ $json.lastName || '' }}",
          "company": "={{ $json.company || '' }}",
          "tags": "={{ ['email-marketing', 'new-lead'] }}"
        }
      },
      "id": "create-crm-contact",
      "name": "Create CRM Contact",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 1,
      "position": [680, 200],
      "credentials": {
        "hubspotApi": {
          "id": "hubspot-credentials",
          "name": "HubSpot API"
        }
      }
    },
    {
      "parameters": {
        "resource": "email",
        "operation": "send",
        "additionalFields": {
          "to": "={{ $json.email }}",
          "subject": "Welcome to Our Newsletter!",
          "html": "<h1>Welcome!</h1><p>Thank you for subscribing to our newsletter. We're excited to have you on board!</p>",
          "from": "noreply@company.com"
        }
      },
      "id": "send-welcome-email",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.sendGrid",
      "typeVersion": 1,
      "position": [900, 200],
      "credentials": {
        "sendGridApi": {
          "id": "sendgrid-credentials",
          "name": "SendGrid API"
        }
      }
    },
    {
      "parameters": {
        "resource": "list",
        "operation": "addMember",
        "additionalFields": {
          "email_address": "={{ $json.email }}",
          "status": "subscribed",
          "merge_fields": {
            "FNAME": "={{ $json.firstName || '' }}",
            "LNAME": "={{ $json.lastName || '' }}",
            "COMPANY": "={{ $json.company || '' }}"
          }
        }
      },
      "id": "add-to-mailchimp",
      "name": "Add to Mailchimp",
      "type": "n8n-nodes-base.mailchimp",
      "typeVersion": 1,
      "position": [900, 400],
      "credentials": {
        "mailchimpApi": {
          "id": "mailchimp-credentials",
          "name": "Mailchimp API"
        }
      }
    },
    {
      "parameters": {
        "resource": "task",
        "operation": "create",
        "additionalFields": {
          "title": "Follow up with new subscriber",
          "description": "New email subscriber: {{ $json.email }}",
          "due_date": "={{ $now.plus({ days: 3 }).toISOString() }}",
          "assignee": "sales-team"
        }
      },
      "id": "create-followup-task",
      "name": "Create Follow-up Task",
      "type": "n8n-nodes-base.asana",
      "typeVersion": 1,
      "position": [1120, 300],
      "credentials": {
        "asanaApi": {
          "id": "asana-credentials",
          "name": "Asana API"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.email }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "handle-invalid-email",
      "name": "Handle Invalid Email",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [680, 400]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"error\": \"Email is required\",\n  \"status\": \"failed\"\n}",
        "options": {}
      },
      "id": "error-response",
      "name": "Error Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [900, 400]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\n  \"message\": \"Subscription successful\",\n  \"status\": \"success\",\n  \"email\": \"{{ $json.email }}\"\n}",
        "options": {}
      },
      "id": "success-response",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [1340, 300]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Validate Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Email": {
      "main": [
        [
          {
            "node": "Create CRM Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Handle Invalid Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create CRM Contact": {
      "main": [
        [
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email": {
      "main": [
        [
          {
            "node": "Add to Mailchimp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to Mailchimp": {
      "main": [
        [
          {
            "node": "Create Follow-up Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Follow-up Task": {
      "main": [
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Handle Invalid Email": {
      "main": [
        [
          {
            "node": "Error Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "createdAt": "2025-01-01T00:00:00.000Z",
      "updatedAt": "2025-01-01T00:00:00.000Z",
      "id": "email-marketing",
      "name": "Email Marketing"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2025-01-01T00:00:00.000Z",
  "versionId": "1.0.0"
}

