{
  "id": "LdR1WNr3yM5Lw9X8",
  "name": "Customs_Tariff_Number_Research V2",
  "tags": [],
  "nodes": [
    {
      "id": "ec7c3dd9-74ee-4008-b32c-da57d6069e30",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -336,
        336
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "0f817acd-9c17-4756-90ba-ff1106edad53",
      "name": "Customs Tariff API Query",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -144,
        336
      ],
      "parameters": {
        "url": "=https://www.zolltarifnummern.de/api/v2/cnSuggest?term={{ encodeURIComponent($json.chatInput) }}&lang=de",
        "options": {
          "timeout": 10000,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "allowUnauthorizedCerts": true
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "User-Agent",
              "value": "n8n-workflow/1.0"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "8d670dda-9b23-4542-bb8f-ce7074beac64",
      "name": "Output Customs Tariff Number",
      "type": "n8n-nodes-base.set",
      "position": [
        48,
        336
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "assignment-1",
              "name": "text",
              "type": "string",
              "value": "={{ $json.suggestions[1].code }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9b92a873-ecb8-43cc-929f-9514bed35c5e",
      "name": "Read Item Descriptions",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        128,
        560
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs/edit?usp=drivesdk",
          "cachedResultName": "Customs Numbers"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "f95221b2-9d6d-4dd2-bd22-7faab04341f9",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        384,
        560
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "60ddfdb2-b326-4cae-bc20-10cf2631a6ae",
      "name": "Write Customs Tariff to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        992,
        576
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "Artikelbeschreibung",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Artikelbeschreibung",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Zolltarifnummer",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Zolltarifnummer",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Artikelbeschreibung"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1nJ_VAeCwOnFwF-t7rFlbftbkAuT35gig9d7YCGsurHs/edit?usp=drivesdk",
          "cachedResultName": "Customs Numbers"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "9b5f275d-136a-4227-9a62-120bc32e0c0e",
      "name": "Customs Tariff API Query Batch",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        592,
        576
      ],
      "parameters": {
        "url": "=https://www.zolltarifnummern.de/api/v2/cnSuggest?term={{ encodeURIComponent($json['Artikelbeschreibung']) }}&lang=de",
        "options": {
          "timeout": 10000,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "allowUnauthorizedCerts": true
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "User-Agent",
              "value": "n8n-workflow/1.0"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "653ef025-1c47-4115-94f3-867138e1f654",
      "name": "Send Completion Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        784,
        352
      ],
      "parameters": {
        "sendTo": "test@example.com",
        "message": "Job completed successfully",
        "options": {},
        "subject": "Completed: Customs Tariff Number Research Finished"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b02dc4a3-b4e0-4bb1-9d8a-112ac0301b87",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        560,
        352
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "bb6f42bd-de6e-4adb-97d2-b89867709d5c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        256
      ],
      "parameters": {
        "color": 6,
        "width": 640,
        "height": 256,
        "content": "## Manual Single Query for Customs Tariff Number\nEnter item description and receive suggestion #1 from the API query"
      },
      "typeVersion": 1
    },
    {
      "id": "6229ef15-b823-48f2-82bb-f81d07f7f976",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        528
      ],
      "parameters": {
        "width": 1552,
        "height": 256,
        "content": "## Batch Query from List\nAll entries in column A \nwill be enriched with customs \ntariff numbers in column B\n(select Google Sheet and tab)"
      },
      "typeVersion": 1
    },
    {
      "id": "7c9e9844-9995-41d6-9ec2-db4a3af10160",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        256
      ],
      "parameters": {
        "color": 4,
        "width": 896,
        "height": 256,
        "content": "## Completion\nNotification email that process \nis finished (configure desired email address)"
      },
      "typeVersion": 1
    },
    {
      "id": "18289af3-a07a-46ef-abed-10d4bc6aec29",
      "name": "Start Query",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -48,
        560
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "31ef430b-a463-4742-bf36-57509464a684",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        256
      ],
      "parameters": {
        "color": 3,
        "width": 416,
        "height": 256,
        "content": "### [Video Tutorial](https://youtu.be/UccIqmMmq7w)\n@[youtube](UccIqmMmq7w)"
      },
      "typeVersion": 1
    },
    {
      "id": "18d3e9ef-6168-482f-bcd7-d05ae1789975",
      "name": "prepare data",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        576
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "assignment-1",
              "name": "Zolltarifnummer",
              "type": "string",
              "value": "={{ $json.suggestions && $json.suggestions[1] ? $json.suggestions[1].code : 'Nicht gefunden' }}"
            },
            {
              "id": "assignment-3",
              "name": "Artikelbeschreibung",
              "type": "string",
              "value": "={{ $('Loop Over Items').item.json['Artikelbeschreibung'] }}"
            },
            {
              "id": "bb2fbbce-b66b-42b6-a639-baa949b763e8",
              "name": "Beschreibung der Zolltarifnummer",
              "type": "string",
              "value": "={{ $json.suggestions[1].value.split(/<br\\s*\\/?>/i)[1].trim() }}"
            },
            {
              "id": "f4389d75-a1f3-4ccd-9a62-0f7544923e02",
              "name": "Score",
              "type": "string",
              "value": "={{ ($json.suggestions[1].score * 100).toFixed(1) + '%' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7e35bde7-5057-41a1-a1a9-e332db984cff",
  "connections": {
    "Aggregate": {
      "main": [
        [
          {
            "node": "Send Completion Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Query": {
      "main": [
        [
          {
            "node": "Read Item Descriptions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "Customs Tariff API Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "prepare data": {
      "main": [
        [
          {
            "node": "Write Customs Tariff to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Customs Tariff API Query Batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Item Descriptions": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Customs Tariff API Query": {
      "main": [
        [
          {
            "node": "Output Customs Tariff Number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Customs Tariff to Sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Customs Tariff API Query Batch": {
      "main": [
        [
          {
            "node": "prepare data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}