{
  "name": "Human In Circuit - Request human review",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            { "name": "api_key" },
            { "name": "circuit_url" },
            { "name": "n8n_public_url" },
            { "name": "external_id" },
            { "name": "inbox_key" },
            { "name": "title" },
            { "name": "summary" },
            { "name": "details_markdown" },
            { "name": "fields", "type": "array" },
            { "name": "initial_values", "type": "object" },
            { "name": "output", "type": "object" },
            { "name": "metadata", "type": "object" },
            { "name": "priority" },
            { "name": "risk" },
            { "name": "callback_auth_value" }
          ]
        }
      },
      "id": "input",
      "name": "Called by another workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ ($json.circuit_url || 'https://humanincircuit.com').replace(/\\/$/, '') + '/v2/reviews' }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ 'Bearer ' + $json.api_key }}"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ ($json.external_id || $execution.id) + '-human-review' }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { external_id: $json.external_id || $execution.id, inbox_key: $json.inbox_key, title: $json.title, summary: $json.summary || $json.title, details_markdown: $json.details_markdown || '', priority: $json.priority || 'normal', risk: $json.risk || 'low', agent: { name: 'n8n', workflow: $workflow.name, tags: ['n8n'] }, metadata: $json.metadata || {}, fields: $json.fields || [], initial_values: $json.initial_values || $json.output || {}, callback: { url: $execution.resumeUrl.replace(/^https?:\\/\\/[^/]+/, ($json.n8n_public_url || 'https://n8n.example.com').replace(/\\/$/, '')), ...($json.callback_auth_value ? { auth_header: 'x-human-in-circuit-token', auth_value: $json.callback_auth_value } : {}) } } }}"
      },
      "id": "submit",
      "name": "Submit review",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [240, 0]
    },
    {
      "parameters": {
        "resume": "webhook",
        "httpMethod": "POST",
        "authentication": "none",
        "options": {}
      },
      "id": "wait",
      "name": "Wait for decision",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [480, 0]
    },
    {
      "parameters": {
        "jsCode": "const payload = $json.body ?? $json;\nreturn [{ json: { ...payload, output: payload.output ?? payload.final_values ?? {} } }];"
      },
      "id": "output",
      "name": "Return decision",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [720, 0]
    }
  ],
  "connections": {
    "Called by another workflow": {
      "main": [[{ "node": "Submit review", "type": "main", "index": 0 }]]
    },
    "Submit review": {
      "main": [[{ "node": "Wait for decision", "type": "main", "index": 0 }]]
    },
    "Wait for decision": {
      "main": [[{ "node": "Return decision", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
