{
  "id": "qr_batch3_csv_20261007",
  "name": "apizt CSV classification - fixed three rows",
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "nodes": [
    {
      "id": "manual",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "csv",
      "name": "CSV fixture",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "jsCode": "const csv = 'row_id,text\\nA01,\"退款迟迟未到账\"\\nA02,\"如何修改登录密码\"\\nA03,\"想了解企业版价格\"';\nconst rows = csv.split('\\n').slice(1).map(line => { const comma = line.indexOf(','); return {row_id:line.slice(0,comma),text:line.slice(comma+1).replace(/^\"|\"$/g,'')}; });\nreturn rows.map(json => ({json}));"
      }
    },
    {
      "id": "http",
      "name": "apizt classify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        0
      ],
      "retryOnFail": false,
      "onError": "continueRegularOutput",
      "parameters": {
        "method": "POST",
        "url": "https://api.apizt.com/v1/chat/completions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({model:\"glm-5.3\",messages:[{role:\"system\",content:\"Classify support messages. Return only a JSON object with row_id and category. Allowed category values: billing, account, sales. Preserve row_id exactly. No tools.\"},{role:\"user\",content:JSON.stringify($json)}],max_tokens:80}) }}",
        "options": {
          "timeout": 60000,
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1000
            }
          }
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID",
          "name": "apizt API Key"
        }
      }
    },
    {
      "id": "validate",
      "name": "Validate and record",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "jsCode": "const rows = $('CSV fixture').all();\nreturn $input.all().map((item,index) => {\n const source=rows[index].json; const body=item.json; let parsed=null;\n const choice=body.choices?.[0]; const finish=choice?.finish_reason??null;\n try { parsed=JSON.parse(choice?.message?.content ?? ''); } catch {}\n const httpStatus=Number(body.error?.statusCode??body.error?.httpCode??body.statusCode??0);\n const hasError=Boolean(body.error);\n const uncertain=hasError && (!httpStatus || httpStatus>=500 || httpStatus===408);\n const valid=!hasError && finish==='stop' && parsed?.row_id===source.row_id && ['billing','account','sales'].includes(parsed?.category);\n const status=valid?'accepted':uncertain?'unknown':'failed';\n return {json:{row_id:source.row_id,text:source.text,status,finish_reason:finish,category:valid?parsed.category:null,expected:{A01:'billing',A02:'account',A03:'sales'}[source.row_id],correct:valid && parsed.category==={A01:'billing',A02:'account',A03:'sales'}[source.row_id],usage:body.usage??null,request_id:body.id??null,error_type:hasError?(httpStatus?'http_'+httpStatus:'network_or_unknown'):(valid?null:'invalid_or_incomplete_output'),error:valid?null:uncertain?'Outcome unknown; check console before retry':'Response rejected, incomplete or failed validation'}};\n});"
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "CSV fixture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CSV fixture": {
      "main": [
        [
          {
            "node": "apizt classify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "apizt classify": {
      "main": [
        [
          {
            "node": "Validate and record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
