{
  "nodes": [
    {
      "id": "973144af-ca9d-4ee9-9096-ccbf97c2b00b",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        0,
        192
      ],
      "parameters": {
        "event": "rowAdded",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit?usp=drivesdk",
          "cachedResultName": "Freight Documentation"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bfc1fb2d-d2e3-46d1-b0cb-b3557fd1cedf",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        224,
        192
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "576648bd-8009-4b2c-9b94-d0f398cfdd80",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        384,
        448
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "c6cda165-a36e-43a0-9f30-4d15ed469846",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        656,
        448
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"valid\": \"\",\n  \"reason\": \"\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e3667b67-4d74-4bab-9356-d0cac6b21646",
      "name": "Send Shipment PDF To Sender",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1696,
        304
      ],
      "parameters": {
        "sendTo": "={{ $('Loop Over Items').item.json['Shipper email'] }}",
        "message": "=Hello {{ $('Loop Over Items').item.json['Shipper / Sender Name & Address'] }},\n\n\ud83d\udce6 Your shipment report is now available!  \nPlease use the link below to download the PDF:\n\n\ud83d\udd17 [View Shipment Report]:{{ $json.data.Files[0].Url }}\n\nShipment ID: {{ $('Loop Over Items').item.json['Shipment ID / Reference Number'] }}\nShipper: {{ $('Loop Over Items').item.json['Shipper / Sender Name & Address'] }}\nReceiver:{{ $('Loop Over Items').item.json['Receiver / Consignee Name & Address'] }}\n\nIf you have any questions, feel free to reply to this email.\n\nBest regards,  \nLogistics Team \ud83d\ude9a\n",
        "options": {
          "appendAttribution": false
        },
        "subject": "\ud83d\udce6 Shipment Report",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "0e0c43bb-aefd-40b6-8ad1-6ebcc1966a81",
      "name": "Send Shipment PDF To Receiver",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1904,
        304
      ],
      "parameters": {
        "sendTo": "={{ $('Loop Over Items').item.json['Receiver email'] }}",
        "message": "=Hello {{ $('Loop Over Items').item.json['Receiver / Consignee Name & Address'] }},\n\n\ud83d\udce6 Your shipment report is now available!  \nPlease use the link below to download the PDF:\n\n\ud83d\udd17 [View Shipment Report]:{{ $json.data.Files[0].Url }}\n\nShipment ID: {{ $('Loop Over Items').item.json['Shipment ID / Reference Number'] }}\nShipper: {{ $('Loop Over Items').item.json['Shipper / Sender Name & Address'] }}\nReceiver:{{ $('Loop Over Items').item.json['Receiver / Consignee Name & Address'] }}\n\nIf you have any questions, feel free to reply to this email.\n\nBest regards,  \nLogistics Team \ud83d\ude9a\n",
        "options": {
          "appendAttribution": false
        },
        "subject": "\ud83d\udce6 Shipment Report",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "59754ad1-bd9c-4cc9-bc9b-22f2487955e7",
      "name": "Get PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1552,
        48
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson"
      },
      "typeVersion": 1
    },
    {
      "id": "150837e5-e9ef-4739-bcd5-db4903d2e77e",
      "name": "PDF Generate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1344,
        48
      ],
      "parameters": {
        "url": "https://v2.convertapi.com/convert/html/to/pdf",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "StoreFile",
              "value": "true"
            },
            {
              "name": "File",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "3d26f8f3-3604-4dd7-b565-0264b361dd1c",
      "name": "Set Shipment Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1120,
        48
      ],
      "parameters": {
        "jsCode": "// Get the first item JSON\nconst item = $('Loop Over Items').first().json;\n\n// Create dynamic HTML content\nconst htmlContent = `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <title>Shipment Report</title>\n  <style>\n    body {\n      font-family: 'Segoe UI', Arial, sans-serif;\n      margin: 30px;\n      color: #222;\n      background-color: #f4f7fb;\n    }\n\n    .header {\n      background: linear-gradient(135deg, #004aad, #007bff);\n      color: white;\n      padding: 25px;\n      text-align: center;\n      border-radius: 12px;\n      margin-bottom: 30px;\n      box-shadow: 0 4px 10px rgba(0,0,0,0.15);\n    }\n\n    .header h1 {\n      margin: 0;\n      font-size: 32px;\n      letter-spacing: 1px;\n    }\n\n    .section {\n      margin-bottom: 25px;\n      padding: 20px;\n      border: none;\n      border-radius: 12px;\n      background-color: white;\n      box-shadow: 0 4px 8px rgba(0,0,0,0.1);\n    }\n\n    .section h2 {\n      margin-top: 0;\n      color: #004aad;\n      font-size: 22px;\n      border-bottom: 2px solid #004aad;\n      padding-bottom: 8px;\n    }\n\n    table {\n      width: 100%;\n      border-collapse: separate;\n      border-spacing: 0;\n      margin-top: 15px;\n      font-size: 16px;\n    }\n\n    th, td {\n      border: 1px solid #ddd;\n      padding: 14px;\n      text-align: left;\n    }\n\n    th {\n      background-color: #004aad;\n      color: white;\n      font-weight: bold;\n      font-size: 16px;\n    }\n\n    tr:nth-child(even) {\n      background-color: #f9faff;\n    }\n\n    tr:hover {\n      background-color: #eef5ff;\n    }\n\n    .footer {\n      margin-top: 40px;\n      text-align: center;\n      font-size: 14px;\n      color: #555;\n      padding: 15px;\n      border-top: 2px solid #ddd;\n    }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <h1>\ud83d\udce6 Shipment Report</h1>\n  </div>\n\n  <div class=\"section\">\n    <h2>Shipment Details</h2>\n    <p><strong>Shipment ID:</strong> ${item['Shipment ID / Reference Number']}</p>\n    <p><strong>Shipper:</strong> ${item['Shipper / Sender Name & Address']}</p>\n    <p><strong>Receiver:</strong> ${item['Receiver / Consignee Name & Address']}</p>\n  </div>\n\n  <div class=\"section\">\n    <h2>Goods Information</h2>\n    <table>\n      <tr>\n        <th>Item</th>\n        <th>Quantity</th>\n        <th>Weight</th>\n        <th>HS Code</th>\n      </tr>\n      <tr>\n        <td>${item['Description of Goods']}</td>\n        <td>${item['Quantity / Units']}</td>\n        <td>${item['Weight / Volume']}</td>\n        <td>${item['HS Codes']}</td>\n      </tr>\n    </table>\n  </div>\n\n  <div class=\"footer\">\n    \ud83d\udea2 Generated on <strong>${item['Carrier Name']}</strong> | Logistics System\n  </div>\n</body>\n</html>\n`;\n\n// Convert HTML to binary format for n8n\nconst buffer = Buffer.from(htmlContent, 'utf8');\nconst binaryData = {\n  data: buffer.toString('base64'),\n  mimeType: 'text/html',\n  fileName: 'Shipment_Report.html',\n};\n\n// Attach binary data to the first item\nitems[0].binary = { data: binaryData };\n\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "baac1620-ded6-49ca-a3a4-af36129ba2db",
      "name": "If Validate",
      "type": "n8n-nodes-base.if",
      "position": [
        832,
        208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2d3548fd-d02b-4fd3-b50f-d2944614cd45",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.valid }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "13e5c2b9-2b1a-4782-b1db-e6e0882d2bd3",
      "name": "Send Mismatch Items Details",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1136,
        304
      ],
      "parameters": {
        "sendTo": "={{ $('Loop Over Items').item.json['Shipper email'] }}",
        "message": "=Dear {{ $('Loop Over Items').item.json['Shipper / Sender Name & Address'] }},\n\n\n**Issue Detected:**  \n{{ $json.output.reason }}\n\nPlease review the shipment details carefully and correct any errors to ensure smooth processing and compliance.\n\n**Shipment Details:**  \n- Receiver: {{ $('Loop Over Items').item.json['Receiver / Consignee Name & Address'] }}\n- Carrier: {{ $('Loop Over Items').item.json['Carrier Name'] }}\n- Port of Loading:  {{ $('Loop Over Items').item.json['Port of Loading / Export'] }}\n- Port of Discharge: {{ $('Loop Over Items').item.json['Port of Discharge / Import'] }}\n- Description of Goods:  {{ $('Loop Over Items').item.json['Description of Goods'] }}\n- Quantity / Units: {{ $('Loop Over Items').item.json['Quantity / Units'] }}\n- Weight / Volume: {{ $('Loop Over Items').item.json['Weight / Volume'] }}\n- HS Codes: {{ $('Loop Over Items').item.json['HS Codes'] }}\n\n\u26a0\ufe0f **Action Required:**  \nPlease verify and correct the shipment information as soon as possible to avoid delays.\n\nThank you for your prompt attention.\n\nBest regards,  \n**Team**  \n",
        "options": {
          "appendAttribution": false
        },
        "subject": "\u26a0\ufe0f Action Required: Shipment Item Mismatch Detected",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "040aecd1-11bc-4bb0-a905-eb299417bf84",
      "name": "Update State",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1344,
        304
      ],
      "parameters": {
        "columns": {
          "value": {
            "State": "Mismatch_Details",
            "Shipment ID / Reference Number": "={{ $('Loop Over Items').item.json[\"Shipment ID / Reference Number\"] }}"
          },
          "schema": [
            {
              "id": "Shipment ID / Reference Number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Shipment ID / Reference Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Shipper / Sender Name & Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Shipper / Sender Name & Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Receiver / Consignee Name & Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Receiver / Consignee Name & Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Carrier Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Carrier Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Port of Loading / Export",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Port of Loading / Export",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Port of Discharge / Import",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Port of Discharge / Import",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Description of Goods",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Description of Goods",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Quantity / Units",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Quantity / Units",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Weight / Volume",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Weight / Volume",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "HS Codes",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "HS Codes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Shipper email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Shipper email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Receiver email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Receiver email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "State",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "State",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Shipment ID / Reference Number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit#gid=0",
          "cachedResultName": "Shipping Details"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit?usp=drivesdk",
          "cachedResultName": "Freight Documentation"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b187abfe-01b8-4ca4-bc9c-1fb8b7cc7d95",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2528,
        304
      ],
      "parameters": {
        "columns": {
          "value": {
            "State": "shipment_pdf_dispatch",
            "Drive_link": "={{ $json.webViewLink }}",
            "Shipment ID / Reference Number": "={{ $('Loop Over Items').item.json[\"Shipment ID / Reference Number\"] }}"
          },
          "schema": [
            {
              "id": "Shipment ID / Reference Number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Shipment ID / Reference Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Shipper / Sender Name & Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Shipper / Sender Name & Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Receiver / Consignee Name & Address",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Receiver / Consignee Name & Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Carrier Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Carrier Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Port of Loading / Export",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Port of Loading / Export",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Port of Discharge / Import",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Port of Discharge / Import",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Description of Goods",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Description of Goods",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Quantity / Units",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Quantity / Units",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Weight / Volume",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Weight / Volume",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "HS Codes",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "HS Codes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Shipper email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Shipper email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Receiver email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Receiver email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "State",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "State",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Drive_link",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Drive_link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Shipment ID / Reference Number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit#gid=0",
          "cachedResultName": "Shipping Details"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit?usp=drivesdk",
          "cachedResultName": "Freight Documentation"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "d591100a-52ef-41bb-adb3-6114d2fc70ab",
      "name": "Validate Shipment details",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        464,
        208
      ],
      "parameters": {
        "text": "=You are an AI assistant for Freight Documentation.\n\nYou are given the following shipment data:\n\nShipment ID:{{ $json['Shipment ID / Reference Number'] }}\nShipper / Sender Name & Address: {{ $json['Shipper / Sender Name & Address'] }}\nReceiver / Consignee Name & Address: {{ $json['Receiver / Consignee Name & Address'] }}\nCarrier Name: {{ $json['Carrier Name'] }}\nPort of Loading / Export: {{ $json['Port of Loading / Export'] }}\nPort of Discharge / Import: {{ $json['Port of Discharge / Import'] }}\nDescription of Goods: {{ $json['Description of Goods'] }}\nQuantity / Units: {{ $json['Quantity / Units'] }}\nWeight / Volume: {{ $json['Weight / Volume'] }}\nHS Codes: {{ $json['HS Codes'] }}\n\nYour task:\n1. Validate all fields for accuracy and compliance according to the following rules:\n   - Shipment ID must be properly formatted.\n   - Sender and Receiver addresses must be complete.\n   - Carrier Name must exist in the \"carrier_Details\" reference list.\n   - Ports must be valid Format..\n   - Description of Goods must match the HS Codes.\n   - Quantity and Weight must be positive numbers and consistent.\n   - HSN Codes must be valid for export/import compliance.\n2. Output **only a JSON object** in the following format:\n\n{\n  \"valid\": true/false,\n  \"reason\": \"Explain the first error found if any; leave empty if all fields are valid.\"\n}\n\nDo not generate any documents or additional explanations. Only return the JSON.\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "ee529711-32e8-40c9-8158-358c43660489",
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2320,
        304
      ],
      "parameters": {
        "name": "={{ $('Loop Over Items').item.json[\"Shipment ID / Reference Number\"] }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "16aQLw-neIIeWXyFFj8UyPEam7xbrby5G",
          "cachedResultUrl": "https://drive.google.com/drive/folders/16aQLw-neIIeWXyFFj8UyPEam7xbrby5G",
          "cachedResultName": "Freight Documentation"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7916dd0b-2cdd-467b-be04-430c1531ef05",
      "name": "Download File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2112,
        304
      ],
      "parameters": {
        "url": "={{ $('Get PDF').item.json.data.Files[0].Url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "883f0258-d1fd-4d5d-90f0-68491fe2b0a8",
      "name": "Carrier Details",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        528,
        448
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "Active",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 839895459,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit#gid=839895459",
          "cachedResultName": "Carrier Details"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit?usp=drivesdk",
          "cachedResultName": "Freight Documentation"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "8d66ceb0-c7a4-4a33-9241-adc129c29711",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        416
      ],
      "parameters": {
        "color": 2,
        "width": 448,
        "height": 112,
        "content": "## Sample Sheet\nhttps://docs.google.com/spreadsheets/d/1FdaaTU8TXMZGKV8w8QikhwLg5Vm0pZbQ8U4vtIWUhEM/edit?gid=0#gid=0"
      },
      "typeVersion": 1
    },
    {
      "id": "cf83f331-f3a0-4d83-970e-fe1b743cc6dc",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        16
      ],
      "parameters": {
        "width": 452,
        "height": 380,
        "content": "## How it works\nThis workflow automates freight documentation processing. When a new shipment row is added to Google Sheets, it validates the data using AI against carrier details and HS codes. Valid shipments generate a professional PDF report that's emailed to both shipper and receiver, then stored in Google Drive. Invalid entries trigger an alert email to the shipper with specific error details.\n\n## Setup steps\n1. Connect Google Sheets OAuth2 credentials\n2. Add Gmail OAuth2 credentials \n3. Set OpenAI API key for validation\n4. Configure ConvertAPI bearer token in PDF Generate node\n5. Connect Google Drive OAuth2 for file storage\n"
      },
      "typeVersion": 1
    },
    {
      "id": "bb0332a2-08e2-415c-a1d9-fe14bef57893",
      "name": "Data Ingestion",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 1112,
        "height": 588,
        "content": "## Data Ingestion & AI Validation\n- Monitors Google Sheet for new shipment rows and processes them one at a time\n- Uses OpenAI to validate shipment data against carrier database and compliance rules"
      },
      "typeVersion": 1
    },
    {
      "id": "8c890b1e-5e21-4e74-a3a7-10dc7ffebc25",
      "name": "PDF Generation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 676,
        "height": 284,
        "content": "## PDF Generation\n\nCreates HTML report and converts to PDF via ConvertAPI"
      },
      "typeVersion": 1
    },
    {
      "id": "d317fc9d-c6a6-4273-be59-da985dac802f",
      "name": "Storage & Tracking",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        208
      ],
      "parameters": {
        "color": 7,
        "width": 1128,
        "height": 396,
        "content": "## Storage and Logging\n\nUploads PDF to Google Drive and updates sheet with status and link."
      },
      "typeVersion": 1
    },
    {
      "id": "9d235372-280a-4019-8d99-a7044be8f5b2",
      "name": "Error Handling",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        208
      ],
      "parameters": {
        "color": 7,
        "width": 548,
        "height": 396,
        "content": "## Error Handling\n\nNotifies shipper of validation errors and logs mismatch state"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Get PDF": {
      "main": [
        [
          {
            "node": "Send Shipment PDF To Sender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Validate": {
      "main": [
        [
          {
            "node": "Set Shipment Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Mismatch Items Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PDF Generate": {
      "main": [
        [
          {
            "node": "Get PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update State": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Carrier Details": {
      "ai_tool": [
        [
          {
            "node": "Validate Shipment details",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Validate Shipment details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Validate Shipment details",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Shipment Data": {
      "main": [
        [
          {
            "node": "PDF Generate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Validate Shipment details",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Validate Shipment details": {
      "main": [
        [
          {
            "node": "If Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Mismatch Items Details": {
      "main": [
        [
          {
            "node": "Update State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Shipment PDF To Sender": {
      "main": [
        [
          {
            "node": "Send Shipment PDF To Receiver",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Shipment PDF To Receiver": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}