Webhook 端點
更新 Webhook 端點
更新 Webhook 端點。url 一定要係絕對 HTTP(S) URL,正式環境建議 HTTPS;status 淨係可以係 active / inactive。subscribed_events 接受公開事件或 ["*"];空 signing_secret 關閉簽名。 帳號端點由 inactive 改為 active 時,如果同一帳號已有其他 active 端點,會回傳 409 account_webhook_already_exists(40008);原本 active 保持 active 嘅更新仍然可以執行。 一般工作區要喺 subscribed_events 明確列出 call.answered、call.ended,先可以收到相應外撥事件。內測工作區亦可以用 *、空陣列或省略訂閱。投遞、重試同死信重播時會重新核對資格同訂閱。message.* 通話記錄獨立。
https://api.unifyport.ai/v1/webhook-endpoints/{endpoint_id}支援渠道
呼叫前準備
在伺服器端使用資源所屬工作區的 X-Api-Key,執行範例前替換所有預留位置。
PATCH 會取代 Webhook 設定。請提交所有需要保留的設定:省略 signing_secret 會停用簽章,省略 subscribed_events 會恢復接收全部公開事件,省略 retry_policy/max_attempts 會恢復預設重試 3 次。先讀取現有設定,並提供自行保存的簽章密鑰。
建立或重新啟用帳號獨立端點時,同一 account_id 只允許一個 active 端點;衝突回傳 409 account_webhook_already_exists(40008)。inactive 帳號端點和工作區端點可有多個。原 active 端點維持 active 時允許更新,歷史多 active 設定也適用。
參數從哪裡取得
- account_id
- 從建立或查詢帳號的回應取得 data.id。帳號屬於 X-Api-Key 對應的工作區。 攞帳號
請求參數
請求標頭
X-Api-Key工作區 API Key,工作區會由呢個標頭解析得出嚟。
Content-Type發送 JSON 請求內容嘅時候請用 application/json。
路徑參數
endpoint_id用嚟識別嗰條 webhook endpoints 路由嘅 ID。
請求內容
account_idbody 中可選嘅公開帳號 ID,例如 acc_example。建立時用嚟綁定帳號,省略就建立工作空間端點;更新時只驗證原有綁定,省略就保留現有歸屬。唔可以切換帳號、將工作空間端點改為帳號端點或清除綁定。唔接受 query、null、空字串、純空白字串或重複欄位。欄位名稱必須精確使用 account_id;body 或 query 中嘅大小寫變體及歸屬唔匹配會回傳 400 invalid_request。明確指定嘅帳號唔存在或唔屬於目前工作空間會回傳 404 account_not_found (20020)。 帳號獨立設定優先於工作空間設定;停用或冇訂閱某類事件唔會回退至工作空間。刪除最後一個獨立端點後,之後嘅首次投遞會恢復繼承。 啟用衝突只檢查同一 account_id 嘅其他 active 端點;工作空間端點唔受呢個限制,具體條件見 status。
minLength: 1 · pattern: \S
url接收 Webhook 嘅絕對 HTTP(S) URL;正式環境建議 HTTPS。
format: uri
status端點狀態:active 或 inactive。建立 active 帳號端點或由 inactive 改為 active 時,如果同一帳號已有其他 active 端點,會回傳 409 account_webhook_already_exists(40008)。inactive 帳號端點同工作空間端點都可以設定多個。原本 active 端點保持 active 嘅更新仍然可以執行,包括歷史多 active 設定;歷史端點唔會自動清理。
enum: active, inactive
subscribed_events[]公開標準事件訂閱。省略、空陣列或包含 * 表示接收工作區可接收嘅公開事件,包括新增嘅 contact.updated,但唔包括 provider.raw_event。只需要指定事件時請明確列出事件名。 訂閱 message.read 亦會收到 WhatsApp 播放回條,data.event.receipt_type 係 played。 一般工作區要喺 subscribed_events 明確列出 call.answered、call.ended,先可以收到相應外撥事件。內測工作區亦可以用 *、空陣列或省略訂閱。投遞、重試同死信重播時會重新核對資格同訂閱。message.* 通話記錄獨立。
signing_secret可選嘅 Webhook 簽名密鑰,例子入面請用佔位符。
retry_policyobject可選嘅重試政策。max_attempts 係首次投遞之後嘅重試次數,預設 3,範圍 0 到 5;0 代表只做首次投遞。
retry_policy可選嘅重試政策。max_attempts 係首次投遞之後嘅重試次數,預設 3,範圍 0 到 5;0 代表只做首次投遞。
max_attempts首次投遞之後嘅重試次數,範圍係 0 到 5。
如何理解結果
檢查回傳設定。驗證投遞前,端點須為 active 並已訂閱相關事件;僅在 signing_enabled 為 true 時驗證簽章。收到事件後先儲存,再回傳 2xx 確認投遞。
回應 200 OK
{
"request_id": "<REQUEST_ID>",
"data": {
"id": "we_example",
"url": "https://example.com/webhook-updated",
"status": "inactive",
"subscribed_events": [
"message.delivered",
"message.read"
],
"signing_enabled": false,
"retry_policy": {
"max_attempts": 1
}
}
}
回應內容
idWebhook 端點識別碼(we_...)。
account_id帳號獨立端點嘅公開帳號 ID;工作空間端點會省略呢個欄位,唔會回傳 null。
minLength: 1
url接收 webhook 派送嘅絕對 HTTP(S) URL;正式環境建議 HTTPS。
format: uri
status端點狀態:active 或者 inactive。
enum: active, inactive
subscribed_events[]派去呢個端點嘅公開標準事件類型;["*"] 即係工作區可接收嘅公開事件,唔包括 provider.raw_event。
signing_enabled設咗簽名密鑰、派送會簽名嗰陣會係 true。
retry_policyobjectAPI 回傳嘅重試設定。max_attempts 統計首次投遞之後嘅重試次數,預設 3,範圍 0 到 5。
retry_policyAPI 回傳嘅重試設定。max_attempts 統計首次投遞之後嘅重試次數,預設 3,範圍 0 到 5。
max_attempts已設定嘅首次投遞後重試次數,範圍係 0 到 5。
回應
200200 OK
請求成功,回應內容嘅例子如上。
400請求錯誤
請求內容、路徑或者參數無效。
401未授權
X-Api-Key 請求標頭缺少或者無效。
403禁止存取
請求已識別,但唔允許執行呢個操作。
404搵唔到資源
搵唔到請求嘅資源;請結合 error.code 同目前操作核對。
409衝突
目前操作同現有嘅渠道帳號或者資源衝突。
500伺服器錯誤
服務遇到咗未預期嘅錯誤。
失敗後如何處理
檢查 HTTP 狀態和 error.code/numeric_code,保留 request_id。依原因修正參數、繼續授權或檢查狀態。重試傳送及寫入前確認上次結果,避免重複操作。 錯誤碼參考
請按目前操作一併讀取 HTTP 狀態、error.code 同 error.numeric_code。數字碼以字串處理。保留 request_id 排查;佢唔係冪等鍵或任務識別碼。
- invalid_request · 10000 · 400
檢查 JSON 請求內容與必填欄位。
處理與重試: 按目前操作同渠道條件修正參數後再請求。重複提交相同嘅無效請求唔會解決錯誤。
示意 JSON;message 會隨實際原因變化 · 400 · 10000
{ "request_id": "req_example", "error": { "code": "invalid_request", "numeric_code": "10000", "message": "Invalid request parameters" } }- invalid_target_workspace · 11003 · 400
工作區覆寫目標為空或格式無效。請移除覆寫請求標頭,改用目標工作區所屬嘅 API Key。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。
處理與重試: 按目前操作同渠道條件修正參數後再請求。重複提交相同嘅無效請求唔會解決錯誤。
示意 JSON;message 會隨實際原因變化 · 400 · 11003
{ "request_id": "req_example", "error": { "code": "invalid_target_workspace", "numeric_code": "11003", "message": "Invalid target workspace" } }- invalid_api_key · 11001 · 401
檢查 API Key 是否正確且已啟用。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 會隨實際原因變化 · 401 · 11001
{ "request_id": "req_example", "error": { "code": "invalid_api_key", "numeric_code": "11001", "message": "Invalid API key" } }- missing_api_key · 11000 · 401
請加入 X-Api-Key 請求標頭。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
範例 · 401 · 11000
{ "request_id": "req_xxx", "error": { "code": "missing_api_key", "numeric_code": "11000", "message": "Missing X-Api-Key header" } }- beta_feature_not_enabled · 41002 · 403
明確訂閱預留嘅 call.incoming 事件需要工作區具備內測資格。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
範例 · 403 · 41002
{ "request_id": "req_example", "error": { "code": "beta_feature_not_enabled", "numeric_code": "41002", "message": "Beta feature not enabled" } }- workspace_override_forbidden · 11002 · 403
請求嘗試使用呢個 API Key 無權使用嘅工作區覆寫。請移除覆寫請求標頭,改用目標工作區所屬嘅 API Key。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。
處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 會隨實際原因變化 · 403 · 11002
{ "request_id": "req_example", "error": { "code": "workspace_override_forbidden", "numeric_code": "11002", "message": "Workspace override is not allowed" } }- account_not_found · 20020 · 404
核對 account_id,並使用帳號所屬工作區的 X-Api-Key。此工作區下未找到的帳號無法使用目前 Key 存取。
處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。
示意 JSON;message 會隨實際原因變化 · 404 · 20020
{ "request_id": "req_example", "error": { "code": "account_not_found", "numeric_code": "20020", "message": "Account not found" } }- target_workspace_not_found · 11004 · 404
覆寫指定嘅工作區不存在或不可用。請核對工作區歸屬,移除覆寫請求標頭並使用目標工作區 API Key;重複請求唔會增加存取權限。
觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。
處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。
示意 JSON;message 會隨實際原因變化 · 404 · 11004
{ "request_id": "req_example", "error": { "code": "target_workspace_not_found", "numeric_code": "11004", "message": "Target workspace not found" } }- account_webhook_already_exists · 40008 · 409
使用 account_id 列出此帳號的獨立端點,更新既有 active 端點。需要切換時,先停用舊 active 端點,再啟用其他端點;不要自動重試建立或重新啟用。
處理與重試: 重新提交前先讀取端點設定同帳號歸屬。PATCH 會取代設定,保留所需訂閱、簽名設定及重試策略。active 名額衝突時更新已有端點,或先停用舊端點再啟用其他端點。
範例 · 409 · 40008
{ "request_id": "req_example_webhook_conflict", "error": { "code": "account_webhook_already_exists", "numeric_code": "40008", "message": "Account already has an active webhook endpoint" } }- update_webhook_endpoint_failed · 40003 · 500
更新 Webhook 端點:未分類錯誤中斷今次改動,需要確認資源最終狀態。
處理與重試: 重新提交前先讀取端點設定同帳號歸屬。PATCH 會取代設定,保留所需訂閱、簽名設定及重試策略。active 名額衝突時更新已有端點,或先停用舊端點再啟用其他端點。
示意 JSON;message 會隨實際原因變化 · 500 · 40003
{ "request_id": "req_example", "error": { "code": "update_webhook_endpoint_failed", "numeric_code": "40003", "message": "Failed to update webhook endpoint" } }- update_webhook_endpoint_failed · 40006 · 500
呢個歸屬範圍內搵唔到目標 Webhook 端點。GET、PATCH 同停用保留各自操作 code 及 HTTP 500,數字原因係 40006。此細分唔適用於冪等 DELETE;端點不存在時刪除傳回 204。
處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。
示意 JSON;message 會隨實際原因變化 · 500 · 40006
{ "request_id": "req_example", "error": { "code": "update_webhook_endpoint_failed", "numeric_code": "40006", "message": "Webhook endpoint not found" } }