HomeGuidesAPI ReferenceChangelogDiscussions
HomeLog In
Guides

Create Webhook

👍

Notice

開通方式:

跟其他 API 方式一樣,請店長或是任一有權限的管理員在 API Auth 授權頁面找到 Webhook 區塊,並勾選 webhook 相關權限後,更新 Open API token 即可使用。(請參考下方截圖)

📘

Webhook 訂閱規範

接收 Webhook 的 url (endpoint) 在收到 webhook 時,必須立即回應 200 OK ,告知 SHOPLINE 開放平台已經收到事件,不需要重新傳送。

通常建議您在收到 webhook 當下馬上回覆,不要等到完成處理通知後才傳送此回應,以避免被 circuit breaker 自動停用 webhook 功能。(若觸發事件量龐大,建議儲存到 queue 成功後立即回應 200 OK,後續再慢慢消化處理)

您的端點應該回應所有通知 :

  • 使用 200 OK HTTPS 回應
  • 在 15 秒以內

請盡快回覆 SHOPLINE 平台正確的 HTTP 狀態碼 200,SHOPLINE 平台在傳送事件訊息到開發者 Webhook 伺服器之後,若是等待幾秒鐘沒有得到任何 HTTP 狀態碼的回覆,就會重複發送最多 3 次;若是一直發生傳送失敗的狀況,SHOPLINE 平台會自動將該 Webhook 伺服器封鎖或進行其他處置,造成開發者的應用服務無法正常運作,請開發者們留意。


Webhook Subscription Guidelines

The URL (endpoint) that receives the webhook must respond with a 200 OK immediately upon receiving the webhook, telling SHOPLINE Open Platform that you received the event and there is no need to resend it.

It is recommended that you respond immediately when receiving the webhook, rather than waiting until the processing is completed and then sending the response. This is to avoid being automatically disabled by SHOPLINE circuit breaker. (If the are many triggered events, it is advisable to store them in a queue and respond with a 200 OK immediately after successful storage, then proceed to handle them gradually.)

Your endpoint should respond to all notifications:

  • Use a 200 OK HTTPS response.
  • Respond within 15 seconds.

If SHOPLINE platform sends the event message to the developer's webhook server and does not receive any HTTP status code response after waiting for a few seconds, it will resend the message up to 3 times. If the sending failure persists, SHOPLINE platform will automatically block the webhook server or take other measures, which may disrupt the normal operation of the developer's application service.

Function

To create (subscribe) a webhook
創建 (訂閱) 一個 webhook

URL

POST <<api_domain>>/v1/webhooks

Request parameters

ParameterTypeDescriptionExample
addressStringURL to receive the webhook
接收 Webhook 的URL
"address": "http://abc.com/webhooks"
topicsString[]Events that trigger the webhook
誘發 webhook 的事件
---
Topic lists
可以訂閱的 topic 清單
"topics": [ "order/create" ]
curl --location --request POST 'https://open.shoplineapp.com/v1/webhooks' \
--header 'Authorization: Bearer d5537cf89992206433b38766fde925567390b56b79fc301da6393c2116e6a3b3' \
--header 'Content-Type: application/json' \
--data-raw '{
    "address": "http://abc.com/webhooks",
    "topics": [
        "order/create"
    ]
}'

Response example

{
    "id": "5fcf3c84d9454d0038be2f43",
    "format": "json",
    "address": "http://abc.com/webhooks",
    "status": "active",
    "merchant_id": "5e840cae77cb07003243f7c7",
    "created_at": "2020-12-08T08:42:44.034+00:00",
    "updated_at": "2020-12-08T08:42:44.034+00:00",
    "topics": [
        "order/create"
    ]
}