{
  "name": "FlowPantry - Automatic birthday offer",
  "nodes": [
    {
      "id": "517112f8-6bfb-4ec0-b019-8e03f2e117ee",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "daysInterval": 1,
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "fade70e3-d529-415e-9aed-51101b5a33b6",
      "name": "Get customers",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "url": "={{$env.CUSTOMERS_URL}}",
        "options": {}
      }
    },
    {
      "id": "ca09aa8b-9fd7-4ba0-8fee-dc5c8b999142",
      "name": "Birthday in 3 days",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const t=new Date(Date.now()+3*864e5);const md=String(t.getMonth()+1).padStart(2,'0')+'-'+String(t.getDate()).padStart(2,'0');const out=[];for(const i of $input.all()){const cs=Array.isArray(i.json)?i.json:(i.json.customers||[i.json]);for(const c of cs){if(c.email&&c.email_opt_in!==false&&String(c.birthday||'').slice(-5)===md)out.push({json:{...c,first:(c.name||'there').split(' ')[0]}});}}return out;"
      }
    },
    {
      "id": "688b9b15-f0d6-4675-978d-cfdce1672d8e",
      "name": "Send birthday offer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.resend.com/emails",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({from: $env.FROM_EMAIL, to: $json.email, subject: 'Happy early birthday, '+$json.first+' 🎉', html: '<p>Hi '+$json.first+',</p><p>Happy birthday from all of us at '+$env.BUSINESS_NAME+'! '+$env.OFFER+'</p><p><small>Unsubscribe: '+$env.UNSUBSCRIBE_URL+'</small></p>'}) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Get customers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get customers": {
      "main": [
        [
          {
            "node": "Birthday in 3 days",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Birthday in 3 days": {
      "main": [
        [
          {
            "node": "Send birthday offer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}