{
  "name": "Dedupe after success",
  "description": null,
  "versionCounter": 1,
  "sourceWorkflowId": null,
  "nodes": [
    {
      "id": "b1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "order-events-safe",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "b2",
      "name": "Not processed yet?",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        220,
        0
      ],
      "parameters": {
        "resource": "row",
        "operation": "rowNotExists",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "processed_events"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "eventId",
              "condition": "eq",
              "keyValue": "={{ $json.body.eventId }}"
            }
          ]
        }
      }
    },
    {
      "id": "b3",
      "name": "Process order",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ],
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  if (item.json.body.fail) throw new Error('downstream failure for ' + item.json.body.eventId);\n}\nreturn $input.all().map(i => ({ json: { eventId: i.json.body.eventId } }));"
      }
    },
    {
      "id": "b4",
      "name": "Mark as processed",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        660,
        0
      ],
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "name",
          "value": "processed_events"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "eventId": "={{ $json.eventId }}"
          },
          "schema": [
            {
              "id": "eventId",
              "displayName": "eventId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Not processed yet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Not processed yet?": {
      "main": [
        [
          {
            "node": "Process order",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process order": {
      "main": [
        [
          {
            "node": "Mark as processed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "nodeGroups": [],
  "settings": {
    "executionOrder": "v1"
  },
  "activeVersion": {
    "versionId": "d47def7d-00a3-4939-8534-5bfb79a9e31b",
    "workflowId": "ipNNfiPyJkCFw8QK",
    "nodes": [
      {
        "id": "b1",
        "name": "Webhook",
        "webhookId": "6f1c2d3e-0000-4000-8000-000000000002",
        "type": "n8n-nodes-base.webhook",
        "typeVersion": 2,
        "position": [
          0,
          0
        ],
        "parameters": {
          "httpMethod": "POST",
          "path": "order-events-safe",
          "responseMode": "onReceived",
          "options": {}
        }
      },
      {
        "id": "b2",
        "name": "Not processed yet?",
        "type": "n8n-nodes-base.dataTable",
        "typeVersion": 1.1,
        "position": [
          220,
          0
        ],
        "parameters": {
          "resource": "row",
          "operation": "rowNotExists",
          "dataTableId": {
            "__rl": true,
            "mode": "name",
            "value": "processed_events"
          },
          "filters": {
            "conditions": [
              {
                "keyName": "eventId",
                "condition": "eq",
                "keyValue": "={{ $json.body.eventId }}"
              }
            ]
          }
        }
      },
      {
        "id": "b3",
        "name": "Process order",
        "type": "n8n-nodes-base.code",
        "typeVersion": 2,
        "position": [
          440,
          0
        ],
        "parameters": {
          "jsCode": "for (const item of $input.all()) {\n  if (item.json.body.fail) throw new Error('downstream failure for ' + item.json.body.eventId);\n}\nreturn $input.all().map(i => ({ json: { eventId: i.json.body.eventId } }));"
        }
      },
      {
        "id": "b4",
        "name": "Mark as processed",
        "type": "n8n-nodes-base.dataTable",
        "typeVersion": 1.1,
        "position": [
          660,
          0
        ],
        "parameters": {
          "resource": "row",
          "operation": "insert",
          "dataTableId": {
            "__rl": true,
            "mode": "name",
            "value": "processed_events"
          },
          "columns": {
            "mappingMode": "defineBelow",
            "value": {
              "eventId": "={{ $json.eventId }}"
            },
            "schema": [
              {
                "id": "eventId",
                "displayName": "eventId",
                "required": false,
                "defaultMatch": false,
                "display": true,
                "type": "string",
                "canBeUsedToMatch": true
              }
            ]
          }
        }
      }
    ],
    "connections": {
      "Webhook": {
        "main": [
          [
            {
              "node": "Not processed yet?",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Not processed yet?": {
        "main": [
          [
            {
              "node": "Process order",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Process order": {
        "main": [
          [
            {
              "node": "Mark as processed",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "nodeGroups": [],
    "authors": "Test Owner",
    "name": null,
    "description": null,
    "autosaved": false,
    "createdAt": "2026-11-19T08:21:59.138Z",
    "updatedAt": "2026-11-19T08:21:59.138Z",
    "workflowPublishHistory": [
      {
        "id": 2,
        "workflowId": "ipNNfiPyJkCFw8QK",
        "versionId": "d47def7d-00a3-4939-8534-5bfb79a9e31b",
        "event": "activated",
        "userId": "d719cbe0-0a1c-4cd9-9cfc-6b6b62b1407f",
        "createdAt": "2026-11-19T08:21:59.209Z"
      }
    ]
  }
}
