{
  "name": "Webhook to CSV",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "signup",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "5d6d30ae-f4b1-43b9-8617-f15b4f03ba7e",
      "name": "On signup",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.2,
      "position": [
        -800,
        0
      ],
      "webhookId": "e56e9d9d-7db4-467c-aca1-cfc1c80a10f5"
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "8938f0ca-b64c-4e6b-97aa-f25fd1ea3de5",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "62a30a54-e650-43aa-89f1-56182c30cb28",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "a8652b08-0cf8-4d55-bcaa-4529dda7f9d2",
              "name": "received_at",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "9f53f324-6b06-4165-adf8-736ec35e98b0",
      "name": "Clean up fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        -560,
        0
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// One CSV line per item, quoted where needed, ending with a newline.\n// Convert to File's CSV mode adds a byte-order mark per chunk and no trailing\n// newline, so a hand-built line is the reliable way to append rows.\nconst esc = (v) => {\n  const s = String(v ?? '');\n  return /[\",\\n]/.test(s) ? '\"' + s.replace(/\"/g, '\"\"') + '\"' : s;\n};\nconst lines = $input.all().map(({ json }) =>\n  [json.name, json.email, json.received_at].map(esc).join(','),\n);\nreturn [{ json: { line: lines.join('\\n') + '\\n' } }];"
      },
      "id": "4554763f-10d8-42a7-9920-4b26bcc9c790",
      "name": "Build CSV line",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -320,
        0
      ]
    },
    {
      "parameters": {
        "operation": "toText",
        "sourceProperty": "line",
        "binaryPropertyName": "data",
        "options": {
          "addBOM": false,
          "fileName": "signups.csv"
        }
      },
      "id": "35b9e6f3-14cb-4de8-aafe-06abf6ed3a63",
      "name": "To text file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.2,
      "position": [
        -80,
        0
      ]
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "/home/hatch/.n8n-files/signups.csv",
        "dataPropertyName": "data",
        "options": {
          "append": true
        }
      },
      "id": "b2205483-e9ca-4e74-ace9-53350b4d3a8f",
      "name": "Append to CSV",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        160,
        0
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "2d6c52f1-8829-444a-8562-173529f365c1",
              "name": "status",
              "type": "string",
              "value": "saved"
            },
            {
              "id": "3916fcdd-6741-4dbe-a8f7-e9f94898f9be",
              "name": "name",
              "type": "string",
              "value": "={{ $('Clean up fields').first().json.name }}"
            },
            {
              "id": "c7b21e0d-258b-4c87-b002-b1484297844b",
              "name": "email",
              "type": "string",
              "value": "={{ $('Clean up fields').first().json.email }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "8c6565ad-4389-40ae-b195-4cb7fcb14c0b",
      "name": "Reply",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        400,
        0
      ]
    }
  ],
  "connections": {
    "On signup": {
      "main": [
        [
          {
            "node": "Clean up fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean up fields": {
      "main": [
        [
          {
            "node": "Build CSV line",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build CSV line": {
      "main": [
        [
          {
            "node": "To text file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "To text file": {
      "main": [
        [
          {
            "node": "Append to CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append to CSV": {
      "main": [
        [
          {
            "node": "Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}