{
  "name": "YES/NO - Tender matching",
  "nodes": [
    {
      "parameters": {},
      "id": "start",
      "name": "Run manually",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "source-id",
              "name": "source_id",
              "value": "example-tender",
              "type": "string"
            },
            {
              "id": "request-id",
              "name": "request_id",
              "value": "={{ 'check-' + $execution.id + '-' + $itemIndex }}",
              "type": "string"
            },
            {
              "id": "question",
              "name": "question",
              "value": "Does this tender request commercial cleaning services in Manchester?",
              "type": "string"
            },
            {
              "id": "text",
              "name": "text",
              "value": "Facilities contract: daily cleaning of commercial offices in Manchester. The buyer requires weekday cleaning, washroom servicing and waste collection across three office buildings.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "input",
      "name": "Input item",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        0
      ],
      "notes": "Fictional sample. Replace the manual trigger with your source event and map its text and item ID here. The sample request ID is stable for node retries within this execution. For cross-execution retries, use a unique source event ID plus check version; change the ID whenever the question or text changes."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://answeryesno.com/v1/check",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $json.request_id }}"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "keypair",
        "bodyParameters": {
          "parameters": [
            {
              "name": "question",
              "value": "={{ $json.question }}"
            },
            {
              "name": "text",
              "value": "={{ $json.text }}"
            }
          ]
        },
        "options": {
          "timeout": 100000,
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1000
            }
          },
          "response": {
            "response": {
              "responseFormat": "json",
              "neverError": false
            }
          }
        }
      },
      "id": "check",
      "name": "Binary check",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        0
      ],
      "notes": "Choose a Header Auth credential: Name Authorization, Value Bearer YOUR_API_KEY. Set a service URL reachable from your n8n instance. Request failures stop this workflow; never treat an error as NO. One successful check uses one credit; same-ID retries with identical input are replayed free for seven days."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "valid-result",
              "leftValue": "={{ typeof $json.result === 'boolean' }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "valid",
      "name": "Valid boolean response?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        720,
        0
      ],
      "notes": "Require an actual boolean before entering YES/NO branches. Missing, null, string and other invalid results stop the workflow; they are never NO."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "result",
              "leftValue": "={{ $json.result }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "branch",
      "name": "YES or NO",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        960,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "source-id",
              "name": "source_id",
              "value": "={{ $('Input item').item.json.source_id }}",
              "type": "string"
            },
            {
              "id": "text",
              "name": "text",
              "value": "={{ $('Input item').item.json.text }}",
              "type": "string"
            },
            {
              "id": "question",
              "name": "question",
              "value": "={{ $('Input item').item.json.question }}",
              "type": "string"
            },
            {
              "id": "result",
              "name": "result",
              "value": "={{ $json.result }}",
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "id": "yes",
      "name": "YES - connect your action",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1200,
        -120
      ],
      "notes": "This node only restores the original item beside the answer. Attach your action for a supported question. Test the rule on representative examples before enabling store actions."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "source-id",
              "name": "source_id",
              "value": "={{ $('Input item').item.json.source_id }}",
              "type": "string"
            },
            {
              "id": "text",
              "name": "text",
              "value": "={{ $('Input item').item.json.text }}",
              "type": "string"
            },
            {
              "id": "question",
              "name": "question",
              "value": "={{ $('Input item').item.json.question }}",
              "type": "string"
            },
            {
              "id": "result",
              "name": "result",
              "value": "={{ $json.result }}",
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "id": "no",
      "name": "NO - connect your action",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1200,
        120
      ],
      "notes": "This node only restores the original item beside the answer. NO means the text does not establish the question; it does not independently prove a fact false. Attach your fallback or review action."
    },
    {
      "parameters": {
        "errorType": "errorMessage",
        "errorMessage": "Invalid API response: expected result to be a boolean. No decision received."
      },
      "id": "invalid",
      "name": "Stop - invalid response",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        960,
        300
      ]
    }
  ],
  "connections": {
    "Run manually": {
      "main": [
        [
          {
            "node": "Input item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Input item": {
      "main": [
        [
          {
            "node": "Binary check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Binary check": {
      "main": [
        [
          {
            "node": "Valid boolean response?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YES or NO": {
      "main": [
        [
          {
            "node": "YES - connect your action",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NO - connect your action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valid boolean response?": {
      "main": [
        [
          {
            "node": "YES or NO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Stop - invalid response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}