Set up webhooks
A webhook sends a notification to a URL you specify when entries or media change. Use it to rebuild a static site when you publish a post, to notify Slack, and so on. This page explains how to set up a webhook in the admin and check whether notifications arrive.
Before you begin
Section titled “Before you begin”- You need the [Webhook の管理](Manage webhooks) permission in the space. Among the built-in roles, [オーナー](Owner) and [管理者](Admin) have it
- Prepare the URL that receives notifications. For a Vercel Deploy Hook, a Netlify Build Hook, or a Slack Incoming Webhook, issue the URL in that service first
Create a webhook
Section titled “Create a webhook”To create a webhook, do the following.
- In the left menu of the admin, click [Webhook](Webhooks).
- Click [Webhook を作成](Create webhook).
- In [名前](Name), enter a name to tell it apart (for example, “本番サイトの再ビルド”).
- In [種類](Type), choose the one that fits the destination (see the “Types” table below).
- In [送信先の URL](Destination URL), enter the URL to send notifications to.
- In [対象のコンテンツタイプ](Target content types), choose the content types to notify about. To notify about changes to all content types and media, leave it as [すべてのコンテンツタイプとメディア](All content types and media).
- In [通知するイベント](Events to notify), check the events you want to be notified of. At first, [エントリーの公開・公開中の更新](Entry published or published entry updated) and [エントリーの削除](Entry deleted) are checked.
- (Optional) In [署名のシークレット](Signing secret), enter a string of 8–256 characters. The receiver uses it to check that a notification came from Hako CMS.
- (Optional) If the destination requires an authentication header, click [ヘッダーを追加](Add header) under [カスタムヘッダー](Custom headers), and enter [ヘッダー名](Header name) and [値](Value).
- Check that [有効にする](Enabled) is checked, then click [作成](Create).
The screen of the webhook you created opens. Next, check that notifications arrive in “Send a test” below.
| Type | What it sends | When to use |
|---|---|---|
| [カスタム](Custom) | JSON that describes what happened | Send to a receiver you built |
| [Vercel(Deploy Hook)](Vercel (Deploy Hook)) | Empty JSON | Rebuild a Vercel site |
| [Netlify(Build Hook)](Netlify (Build Hook)) | Empty JSON | Rebuild a Netlify site |
| [Slack(Incoming Webhook)](Slack (Incoming Webhook)) | Text such as “記事「…」を公開しました” (Published post “…”) | Notify a Slack channel |
With [Vercel(Deploy Hook)] and [Netlify(Build Hook)], if notifications that have not been sent yet have piled up, they are sent together as one. Even if you publish many entries in a row, the build does not run many times.
The shape of the JSON sent by [カスタム](Custom) and how to verify the signature are in Receive webhooks.
Events
Section titled “Events”| Name on screen | Event name | When it is sent |
|---|---|---|
| [エントリーの公開・公開中の更新](Entry published or published entry updated) | entry.published |
An entry was published. A published entry was fixed and published |
| [下書きの保存](Draft saved) | entry.draft_saved |
A draft was saved (including when newly created) |
| [公開終了](Unpublished) | entry.unpublished |
Publishing was stopped |
| [エントリーの削除](Entry deleted) | entry.deleted |
An entry was deleted |
| [予約公開の失敗](Scheduled publishing failed) | entry.schedule_failed |
Scheduled publishing could not run because the entry did not meet the publishing rules |
| [メディアの追加](Media added) | media.uploaded |
Media was uploaded |
| [メディアの削除](Media deleted) | media.deleted |
Media was deleted |
- Notifications are sent for writes with an API key as well as for operations in the admin
- When scheduled publishing and scheduled unpublishing run, [エントリーの公開・公開中の更新] and [公開終了] are also sent
- Nothing is sent when a draft is discarded
- You can choose media events only when [対象のコンテンツタイプ](Target content types) is set to [すべてのコンテンツタイプとメディア](All content types and media)
Send a test
Section titled “Send a test”On the webhook’s screen, click [テストの送信](Send test).
A test notification is sent immediately, and the result ([成功](Succeeded) or [失敗](Failed), and the status code the destination returned) appears next to the button. The event of a test notification is [テスト](Test) (ping). Even if it fails, it is not resent.
With [Vercel(Deploy Hook)] and [Netlify(Build Hook)], even a test actually starts a build.
Check whether notifications arrived (delivery history)
Section titled “Check whether notifications arrived (delivery history)”Under [送信履歴](Delivery history) at the bottom of the webhook’s screen, sent notifications are listed newest first.
| Column | Contents |
|---|---|
| [日時](Date and time) | The date and time it was sent |
| [イベント](Event) | The event sent |
| [結果](Result) | [成功](Succeeded), [失敗](Failed), or [送信待ち](Pending), and the status code the destination returned |
| [送信回数](Attempts) | The number of times it was sent (including resends) |
Click [日時] to open [送った本文](Sent body) of that notification and the destination’s [応答](Response). While a resend is pending, the date and time appear after “次の再送:” (Next resend:).
Delivery history is deleted after 30 days.
When delivery fails
Section titled “When delivery fails”A delivery fails when the destination returns anything other than 2xx, when it cannot connect to the destination, or when there is no response within 10 seconds. Redirects (3xx) also count as failures.
Failed notifications are resent automatically up to 5 times, with intervals of 30 seconds, 2 minutes, 10 minutes, 1 hour, and 6 hours.
If you want to resend right away after fixing the destination, click [日時] for that notification in [送信履歴](Delivery history) to open it, then click [もう一度送る](Send again). “送信を予約しました” (Delivery scheduled) is shown, and a notification with the same content is sent again from the start.
Change, pause, or delete a webhook
Section titled “Change, pause, or delete a webhook”Change the values in the form on the webhook’s screen, then click [保存](Save). “保存しました” (Saved) is shown.
- Secret: In [署名のシークレット](Signing secret), choose from [変えない](Keep), [新しくする](Renew), and [消す](Remove). If you choose [消す], notifications are no longer signed
- Pause temporarily: Uncheck [有効にする](Enabled) and click [保存]. The list shows [無効](Disabled), and notifications are no longer sent. While paused, you can still use [テストの送信](Send test)
- Delete: Click [Webhook を削除](Delete webhook) in the upper right, then click [Webhook を削除] again on the confirmation screen. The delivery history is also deleted
- Publish one entry of a target content type (Write and publish entries).
- On the [Webhook](Webhooks) screen, click the name of the webhook you created. You can also see the last result in the [最後の送信](Last delivery) column of the list.
- Check that [エントリーの公開・公開中の更新](Entry published or published entry updated) appears at the top of [送信履歴](Delivery history) with [成功](Succeeded).
Notifications are usually sent 1–2 seconds after the operation.