n8n Foundation 課程練習中 Sendorders 的問題

描述問題/錯誤/問題

在向 n8n 網站發送訂單時,我收到以下錯誤。我檢查了空格、計算等,但找不到錯誤源。當我的所有節點單獨執行時都能完美執行

錯誤訊息是什麼(如果有的話)?您的請求無效或服務無法處理。 您的訂單總額不正確。請確保您正確計算了總額。

請分享您的工作流程

{
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6e58682d-4337-46a8-a36f-a6047502bfe7",
              "name": "order_id",
              "value": "={{ $json.order_id }}",
              "type": "string"
            },
            {
              "id": "2a009df0-7d77-43e6-9e91-a70e004bb17f",
              "name": "customer_name",
              "value": "={{ $json.customer_name }}",
              "type": "string"
            },
            {
              "id": "c36c31fc-c9a7-4dcb-8002-c7434369ea78",
              "name": "region",
              "value": "={{ $json.region }}",
              "type": "string"
            },
            {
              "id": "a6ad9769-cf53-4e2d-b27f-8869ec1506d3",
              "name": "status",
              "value": "={{ $json.status }}",
              "type": "string"
            },
            {
              "id": "ea21f188-1793-4fbc-80b4-14d080492695",
              "name": "order_total",
              "value": "={{Math.round($json.quantity * $json.unit_price)}}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        16,
        -112
      ],
      "id": "e5206f2a-e49f-4f97-a253-f42bbdee3f20",
      "name": "SetOrderTotals"
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "orders",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        608,
        -320
      ],
      "id": "f4a9b2b7-cbb5-4092-adae-82a31b6faadf",
      "name": "AggregateOrders"
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "C0BEZ3AKS9E",
          "mode": "list",
          "cachedResultName": "test"
        },
        "text": "=\"銷售管道完成。已處理 50 筆訂單,38 筆已交付。\"\n\"北部訂單總額:\" {{ $json.region[0].average_order_total }}\n\"南部訂單總額:\" {{ $json.region[2].average_order_total }}\n\"西部訂單總額:\" {{ $json.region[1].average_order_total }}\n\"東部訂單總額:\" {{ $json.region[3].average_order_total }}",
        "otherOptions": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.5,
      "position": [
        816,
        -416
      ],
      "id": "27fbb4f2-ab2a-4977-bef1-5350b8a52c03",
      "name": "SendToSlack",
      "webhookId": "5a4cba28-edf6-40b0-b14f-d68952cccf47",
      "credentials": {
        "slackApi": {
          "id": "JsMFdrKSTabhvlb7",
          "name": "Slack 帳戶"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://learn.app.n8n.cloud/webhook/course/n8n101/process-orders",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-assessment-id",
              "value": "dcaececa5196aa91d2a41fc5b5b53ec8"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "orders",
              "value": "={{ $json.orders }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        816,
        -224
      ],
      "id": "2a053049-1a4b-46f0-abf1-3787c72a1297",
      "name": "SendOrders",
      "credentials": {
        "httpHeaderAuth": {
          "id": "Ga9QOladMz18EL6I",
          "name": "n8n 學院 API 金鑰"
        }
      }
    },
    {
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "sum",
              "field": "order_total"
            },
            {
              "field": "order_total"
            },
            {
              "aggregation": "average",
              "field": "order_total"
            }
          ]
        },
        "fieldsToSplitBy": "region",
        "options": {}
      },
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "position": [
        208,
        -320
      ],
      "id": "91cd6ef5-16d0-4ea0-89a6-b5d2499b1681",
      "name": "SummarizebyRegion"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c271aab4-45e9-4cd8-bc1e-5fee1682718a",
              "name": "sum_order_total",
              "value": "={{ Math.round($json.sum_order_total *100)/100}}",
              "type": "number"
            },
            {
              "id": "8a43ca44-257c-4d5e-9240-396005282a88",
              "name": "count_order_total",
              "value": "={{ $json.count_order_total }}",
              "type": "number"
            },
            {
              "id": "4e9f85c6-ec6e-4a80-bd09-024fadd61c5f",
              "name": "average_order_total",
              "value": "={{ Math.round($json.average_order_total*100)/100 }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        416,
        -320
      ],
      "id": "ea9206a9-c0e7-4836-9194-9a07c0826961",
      "name": "編輯欄位"
    }
  ],
  "connections": {
    "SetOrderTotals": {
      "main": [
        [
          {
            "node": "SummarizebyRegion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AggregateOrders": {
      "main": [
        [
          {
            "node": "SendToSlack",
            "type": "main",
            "index": 0
          },
          {
            "node": "SendOrders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SummarizebyRegion": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AggregateOrders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "7134812ff1766ac00dec6d0b790eac6d9b713a9539f0e1c05a87cf2a2442a32d"
  }
}

您的請求無效或服務無法處理
您的訂單總額不正確。請確保您正確計算了總額。


有關您的 n8n 設置的資訊

  • n8n 版本:Community
  • 資料庫(預設值:SQLite):
  • n8n EXECUTIONS_PROCESS 設置(預設值:own, main):
  • 運行 n8n 方式(Docker、npm、n8n cloud、桌面應用程式):
  • 作業系統:Windows

Hi Venu,

「您的訂單總額不正確」這個錯誤幾乎總是指向您的 SendOrders (HTTP 請求) 節點中的 JSON 承載格式問題。

當您在值欄位中使用 ={{ $json.orders }} 時,n8n 通常會預設將數據作為字符串傳遞,但 n8n Academy API 端點特別需要一個包含訂單陣列的 JSON 物件

以下是修復方法:

  1. 變更主體內容類型: 在您的 SendOrders 節點中,確保啟用了傳送主體選項,但請尋找「JSON」或「主體參數」之類的選項,並確保它不會強制將數據轉換為字符串格式。

  2. 正確使用運算式編輯器: 在您的 orders 主體參數的欄位中,嘗試使用強制 JSON 物件結構的運算式:={{ JSON.stringify($json.orders) }},或者更好的做法是,如果節點支持,將主體參數類型變更為 JSON,然後直接使用 {{ $json.orders }},不加引號。

  3. 檢查您的 SetOrderTotals 節點: 您正在使用 Math.round($json.quantity * $json.unit_price)。仔細檢查您的輸入數據是否包含隱藏的字符串或空值。如果 quantityunit_price 被解釋為字符串,數學運算可能會無聲地失敗或產生意外的類型。嘗試將它們包裝在 Number() 中:={{ Math.round(Number($json.quantity) * Number($json.unit_price)) }}

    要確切查看 API「看到」的內容,請添加一個 Webhook 節點或使用 Webhook.site 之類的服務來檢查來自您 SendOrders 節點的精確傳出承載。如果 API 返回 400 錯誤,幾乎肯定是因為它收到了字符串而不是預期的 JSON 陣列。

    如果這解決了驗證錯誤,請告訴我!

    祝好,Swapnil swapnilailabs.com

嗨 Swapnil

感謝你的迅速回覆。讓我說明我在發布這個問題之前所做的事情

  1. 我檢查了所有節點,確認訂單總額的資料類型是否正確。它被設定為數字
  2. 在「傳送」節點中
    1. 在本文中,「本文內容類型」是 JSON
    2. 指定欄位:
      名稱:orders
    3.     值:{{ $json.orders }}
      

所有節點執行完美無誤。

我也試過 Webhook,那裡也沒有錯誤。

以下是 webhook 結果

{“orders”:[{“sum_order_total”:5348,“count_order_total”:16,“average_order_total”:334.25,“region”:“north”},{“sum_order_total”:2507,“count_order_total”:10,“average_order_total”:250.7,“region”:“west”},{“sum_order_total”:2353,“count_order_total”:14,“average_order_total”:168.07,“region”:“south”},{“sum_order_total”:2263,“count_order_total”:10,“average_order_total”:226.3,“region”:“east”}]}

@venu_nair

你可能需要再次比較你的工作流程與說明,因為我看到你上面的分支比我上次做的時候多了一些節點。

大家好,

我遇到了相同的工作流程錯誤,該工作流程已分享在 URL Course | n8n Platform

以下是我的工作流程和錯誤訊息。

任何幫助發現問題都非常感謝!:slight_smile:

工作流程

工作流程代碼

Section 2 - Sales Data Pipeline.json (5.6 KB)

最後節點 - SendOrders 中獲得的錯誤

{
“errorMessage”: “您的請求無效或無法被服務處理”,
“errorDescription”: “您的訂單總計不正確。請確保您正確計算總計。”,
“errorDetails”: {
“rawErrorMessage”: [
“422 - “{\“error\”:\“您的訂單總計不正確。請確保您正確計算總計。\”}””
],
“httpCode”: “422”
},
“n8nDetails”: {
“nodeName”: “SendOrders”,
“nodeType”: “n8n-nodes-base.httpRequest”,
“nodeVersion”: 4.4,
“itemIndex”: 0,
“time”: “03/07/2026, 14:12:47”,
“n8nVersion”: “2.27.5 (Self Hosted)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“NodeApiError: 您的請求無效或無法被服務處理”,
" at ExecuteContext.execute (C:\Users\Jaideep Satghare\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-nodes-base\nodes\HttpRequest\V3\HttpRequestV3.node.ts:869:16)“,
" at WorkflowExecute.executeNode (C:\Users\Jaideep Satghare\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1067:8)”,
" at WorkflowExecute.runNode (C:\Users\Jaideep Satghare\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1367:11)“,
" at C:\Users\Jaideep Satghare\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:1829:27”,
" at C:\Users\Jaideep Satghare\AppData\Roaming\npm\node_modules\n8n\node_modules\n8n-core\src\execution-engine\workflow-execute.ts:2521:11"
]
}
}

@Jaideep_Satghare,請根據說明檢查你的「SetOrderTotals」節點的「order_total」欄位設定。我看到它有所不同。

另外,你的問題有點不同,所以值得開一個新貼文,這樣其他人也可以幫助你,謝謝。

@kristinker ,感謝你的回覆。:smiley:

我故意使用 Math 四捨五入函式修改「order_total」欄位,以強制進行整數轉換。

儘管如此,我還是找到了問題所在——欄位名稱中有尾部空格。我使用的是「order_total 」而不是「order_total」。我修正後就正常運作了。

感謝你要求我重新檢查該節點。:smiley:

就我而言,這個問題可以關閉了。我會在未來針對類似問題開啟新的討論串。