{
  "name": "DataSnack: Jev answers, code checks, your AI takes the rest",
  "nodes": [
    {
      "id": "n1",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "n2",
      "name": "Example request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "parameters": {
        "jsCode": "// Replace with your trigger's data, as the gate's input fields.\nreturn [\n  {json: {today: '2026-11-18', customer_tier: 'plus', email: 'Hi, the $40 lamp arrived last week and I changed my mind. Can I get a refund?'}},\n  {json: {today: '2026-11-18', customer_tier: 'standard', email: 'I want my money back for the thing I bought a while ago.'}},\n];"
      }
    },
    {
      "id": "n3",
      "name": "Decide",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "parameters": {
        "method": "POST",
        "url": "https://datasnack.ai/v1/gates/refund-emails/decide",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({input: $json}) }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=n8n-{{ $execution.id }}-{{ $itemIndex }}"
            }
          ]
        }
      },
      "retryOnFail": true,
      "maxTries": 3
    },
    {
      "id": "n4",
      "name": "Not confirmed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.decided_by.tier }}",
              "rightValue": "none",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "n5",
      "name": "Your own AI",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        880,
        -100
      ],
      "parameters": {
        "jsCode": "// Replace this node with your own AI (an OpenAI or Anthropic node) or an approval step (Slack, Gmail or Teams:\n// Send and wait for response), and map its answer to the gate's answer fields below.\nreturn $input.all().map(item => ({json: {\n  decision_id: item.json.decision_id,\n  answer: {decision: 'ask'},\n  source: 'model',\n  who: 'our AI'\n}}));"
      }
    },
    {
      "id": "n6",
      "name": "Record the answer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        -100
      ],
      "parameters": {
        "method": "POST",
        "url": "=https://datasnack.ai/v1/decisions/{{ $json.decision_id }}/feedback",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({output: $json.answer, source: $json.source, who: $json.who}) }}",
        "options": {}
      },
      "retryOnFail": true,
      "maxTries": 3
    },
    {
      "id": "n7",
      "name": "Use the answer",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        880,
        100
      ],
      "parameters": {}
    },
    {
      "id": "n8",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        -320
      ],
      "parameters": {
        "width": 640,
        "height": 260,
        "content": "## DataSnack gate\n1. Create a **Header Auth** credential: name `Authorization`, value `Bearer dsk_...` (an API key from datasnack.ai/app/keys), and pick it in both HTTP nodes.\n2. Create the gate from the **Refund emails** template (or change `refund-emails` in **Decide** to your gate's slug).\n3. Once the gate acts, what code confirms comes out of the false branch; what it cannot comes out of the true branch.\n4. Replace **Your own AI** with your AI node or an approval step. The answer you record is repeated for the same request and the gate learns from it.\n\nDocs: datasnack.ai/docs#n8n"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Example request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Example request": {
      "main": [
        [
          {
            "node": "Decide",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide": {
      "main": [
        [
          {
            "node": "Not confirmed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Not confirmed?": {
      "main": [
        [
          {
            "node": "Your own AI",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Use the answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your own AI": {
      "main": [
        [
          {
            "node": "Record the answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
