> For the complete documentation index, see [llms.txt](https://doc.thordata.com/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.thordata.com/doc/zh-hk/web-scraper-api/ji-cheng/webhook-ji-cheng.md).

# Webhook 集成

#### Webhook 集成功能說明：

通過 Webhook 集成功能，您可以在 Thordata Web Scraper 抓取任務中發生特定事件時，自動向指定系統發送通知，從而實時監控任務狀態或將數據推送到其他服務。Webhook 支持動態數據注入，方便後續的自動化處理或業務聯動。

**集成設定：**

1. **集成功能名稱**\
   用於識別和管理此 Webhook 配置。建議自定義一個清晰且易於理解的名稱，以便後續查看和維護。
2. **事件類型**\
   您可以為以下任務事件設定觸發通知：

* 執行中：任務正在執行
* 任務成功：抓取任務已成功完成並返回結果
* 任務失敗：抓取任務沒有返回數據或發生了錯誤

3. **發送通知的方式**\
   當選定事件發生時，系統將向您設定的 URL 發送一條 HTTP POST 請求，請求體為 JSON 格式，內容可自定義，並可透過變數動態注入事件資料。

&#x20;      ① **有效負載（Payload）**\
&#x20;      格式說明：Payload 模板必須是合法的 JSON 字串，並可使用雙大括號 {{ }} 引用變數，例如：

```sh
{
  "userId": "{{userId}}",
  "eventType": "{{eventType}}",
  "createdAt": "{{createdAt}}",
  "eventData": "{{eventData}}",
  "resource": "{{resource}}"
}
```

&#x20;        ② 可用變數：

<table><thead><tr><th width="129">變數名稱</th><th width="99">類型</th><th>說明</th></tr></thead><tbody><tr><td>userId</td><td>string</td><td>觸發事件的 Thordata 使用者 ID</td></tr><tr><td>createdAt</td><td>string</td><td>Webhook 觸發時間（ISO 格式）</td></tr><tr><td>eventType</td><td>string</td><td>目前觸發的事件類型</td></tr><tr><td>eventData</td><td>Object</td><td>與該事件相關的上下文資料</td></tr><tr><td>resource</td><td>Object</td><td>事件資源的詳細資料（如檔案連結、任務 ID 等）</td></tr><tr><td>globals</td><td>Object</td><td>目前事件日期（ISO 8601 格式）</td></tr></tbody></table>

&#x20;       ③ 示例：

```sh
{
    "userId": 3406
    "userName": "Thor84******",
    "createdAt": "2025-06-07T06:33:14Z",
    "eventType": "ACTOR.RUN.SUCCEEDED",
    "eventData": {
        "prodect_id": "3",
        "apiRunId": "2e9ddee0582a********************"
 },
    "resource": {
        "taskId": "2e9ddee0582a********************",
        "url": "{\"spider_errors\":true,\"spider_id\":\"3\",\"spider_parameters\":[{\"url\":\"https://www.amazon.com/dp/B0DPMHRZ1W?th=1\\u0026psc=1\"}]}",
        "apiKey": "289f5c53e47d616********************",
        "apiUrl": "",
        "apiCode": 400,
        "apiResponseTime": 28000,
        "apiErrorMsg": "",
        "apiResult": "",
        "errorNumber": 1,
        "successRate": 0,
        "runseconds：12340
        "detail：Completed! 26 requests in total: 26 successful, 0 failed
        "flow": 1765,
        "fileSize": 1765,
        "type": 0,
        "csvUrl": "https://th-scrapers-1303252866.cos.na-siliconvalley.myqcloud.com/scrapers/thordata/2025/06/07/2e9ddee0582a40a9****************.csv",
        "jsonUrl": "https://th-scrapers-1303252866.cos.na-siliconvalley.myqcloud.com/scrapers/thordata/2025/06/07/2e9ddee0582a40a9****************.json",
        "audioUrl": "",
        "videoUrl": ""
        "subtitleUrl": ""    
        "createdAt": "2025-06-07T14:33:14+08:00",
        "finishedAt": "2025-06-07T14:33:44+08:00",  

}
```

&#x20;       **對應說明：**

<table><thead><tr><th width="384">中文名稱</th><th>對應名</th></tr></thead><tbody><tr><td>使用者ID</td><td>userId</td></tr><tr><td>使用者帳號ID</td><td>userName</td></tr><tr><td>建立時間</td><td>createdAt</td></tr><tr><td>狀態：成功/失敗</td><td>eventType</td></tr><tr><td>事件的相關資料</td><td>eventData</td></tr><tr><td>產品唯一編號</td><td>prodect_id</td></tr><tr><td>API 任務 ID</td><td>apiRunId</td></tr><tr><td>任務資源</td><td>resource</td></tr><tr><td>任務 ID</td><td>taskId</td></tr><tr><td>抓取參數</td><td>url</td></tr><tr><td>抓取 Token</td><td>apiKey</td></tr><tr><td>API 請求 URL</td><td>apiUrl</td></tr><tr><td>API 回應碼</td><td>apiCode</td></tr><tr><td>回應時間</td><td>apiResponseTime</td></tr><tr><td>錯誤訊息</td><td>apiErrorMsg</td></tr><tr><td>API 結果</td><td>apiResult</td></tr><tr><td>錯誤次數</td><td>errorNumber</td></tr><tr><td>成功率</td><td>successRate</td></tr><tr><td>執行秒數</td><td>runseconds</td></tr><tr><td>任務細節</td><td>detail</td></tr><tr><td>流量消耗</td><td>flow</td></tr><tr><td>檔案大小</td><td>fileSize</td></tr><tr><td>抓取類型</td><td>type</td></tr><tr><td>CSV 下載鏈接</td><td>csvUrl</td></tr><tr><td>JSON 下載鏈接</td><td>jsonUrl</td></tr><tr><td>音訊鏈接</td><td>audioUrl</td></tr><tr><td>影片鏈接</td><td>videoUrl</td></tr><tr><td>字幕鏈接</td><td>subtitleUrl</td></tr><tr><td>任務開始時間</td><td>createdAt</td></tr><tr><td>任務結束時間</td><td>finishedAt</td></tr></tbody></table>

4. **Headers 模板（可選）**\
   Headers 模板是一個類似 JSON 的字串，您可在其中向 webhook 請求的預設 header 添加附加資訊。您可以像在 Payload 模板中一樣傳遞變數（包括使用字串插值與可用變數）。生成的 headers 必須是有效的 JSON 物件，且值只能為字串。

&#x20;      請注意，以下鍵是系統預設且會被覆蓋：

* Host：請求 URL
* Content-Type：application/json
* Webhook：Tasks 值
* Webhook-Dispatch-Id：Tasks id
* Request-Origin

如果您需要更多幫助，請通過郵箱 <support@thordata.com> 聯繫我們。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.thordata.com/doc/zh-hk/web-scraper-api/ji-cheng/webhook-ji-cheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
