Skip to content

Commit d95c43a

Browse files
Add /webhooks route (#3336)
--------- Co-authored-by: Mubelotix <[email protected]>
1 parent 5d73023 commit d95c43a

18 files changed

+428
-7
lines changed

.code-samples.meilisearch.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,35 @@ export_post_1: |-
14791479
}
14801480
}
14811481
}'
1482+
webhooks_get_1: |-
1483+
curl \
1484+
-X GET 'MEILISEARCH_URL/webhooks'
1485+
webhooks_get_single_1: |-
1486+
curl \
1487+
-X GET 'MEILISEARCH_URL/webhooks/WEBHOOK_UUID'
1488+
webhooks_post_1: |-
1489+
curl \
1490+
-X POST 'MEILISEARCH_URL/webhooks' \
1491+
-H 'Content-Type: application/json' \
1492+
--data-binary '{
1493+
"url": "WEBHOOK_TARGET_URL",
1494+
"headers": {
1495+
"authorization": "SECURITY_KEY",
1496+
"referer": "https://example.com"
1497+
}
1498+
}'
1499+
webhooks_patch_1: |-
1500+
curl \
1501+
-X PATCH 'MEILISEARCH_URL/webhooks/WEBHOOK_UUID' \
1502+
-H 'Content-Type: application/json' \
1503+
--data-binary '{
1504+
"header": {
1505+
"referer": null
1506+
}
1507+
}'
1508+
webhooks_delete_1: |-
1509+
curl \
1510+
-X DELETE 'MEILISEARCH_URL/webhooks/WEBHOOK_UUID'
14821511
14831512
### Code samples for experimental features
14841513
experimental_get_metrics_1: |-

assets/misc/meilisearch-collection-postman.json

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"info": {
3-
"_postman_id": "f4b62ec3-0403-44ba-b6f4-640badbbd1b2",
4-
"name": "Meilisearch v1.16",
3+
"_postman_id": "a0638dc7-4c40-4c37-822d-bf342771238d",
4+
"name": "Meilisearch latest",
55
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
66
"_exporter_id": "25294324"
77
},
@@ -3044,6 +3044,125 @@
30443044
}
30453045
]
30463046
},
3047+
{
3048+
"name": "Webhooks",
3049+
"item": [
3050+
{
3051+
"name": "Get all webhooks",
3052+
"request": {
3053+
"method": "GET",
3054+
"header": [],
3055+
"url": {
3056+
"raw": "{{url}}/webhooks",
3057+
"host": [
3058+
"{{url}}"
3059+
],
3060+
"path": [
3061+
"webhooks"
3062+
]
3063+
}
3064+
},
3065+
"response": []
3066+
},
3067+
{
3068+
"name": "Get one webhook",
3069+
"request": {
3070+
"method": "GET",
3071+
"header": [],
3072+
"url": {
3073+
"raw": "{{url}}/webhooks/WEBHOOK_UUID",
3074+
"host": [
3075+
"{{url}}"
3076+
],
3077+
"path": [
3078+
"webhooks",
3079+
"WEBHOOK_UUID"
3080+
]
3081+
}
3082+
},
3083+
"response": []
3084+
},
3085+
{
3086+
"name": "Create a webhook",
3087+
"request": {
3088+
"method": "POST",
3089+
"header": [
3090+
{
3091+
"key": "Content-Type",
3092+
"value": "application/json",
3093+
"type": "text"
3094+
}
3095+
],
3096+
"body": {
3097+
"mode": "raw",
3098+
"raw": "{\n \"url\": \"WEBHOOK_TARGET_URL\",\n \"headers\": {\n \"authorization\": \"SECURITY_KEY\",\n \"referer\": \"https://example.com\"\n }\n}"
3099+
},
3100+
"url": {
3101+
"raw": "{{url}}/webhooks",
3102+
"host": [
3103+
"{{url}}"
3104+
],
3105+
"path": [
3106+
"webhooks"
3107+
]
3108+
}
3109+
},
3110+
"response": []
3111+
},
3112+
{
3113+
"name": "Update a webhook",
3114+
"request": {
3115+
"method": "PATCH",
3116+
"header": [
3117+
{
3118+
"key": "Content-Type",
3119+
"value": "application/json",
3120+
"type": "text"
3121+
}
3122+
],
3123+
"body": {
3124+
"mode": "raw",
3125+
"raw": "{\n \"header\": {\n \"referer\": null\n }\n}"
3126+
},
3127+
"url": {
3128+
"raw": "{{url}}/webhooks/WEBHOOK_UUID",
3129+
"host": [
3130+
"{{url}}"
3131+
],
3132+
"path": [
3133+
"webhooks",
3134+
"WEBHOOK_UUID"
3135+
]
3136+
}
3137+
},
3138+
"response": []
3139+
},
3140+
{
3141+
"name": "Delete a webhook",
3142+
"request": {
3143+
"method": "DELETE",
3144+
"header": [
3145+
{
3146+
"key": "Content-Type",
3147+
"value": "application/json",
3148+
"type": "text"
3149+
}
3150+
],
3151+
"url": {
3152+
"raw": "{{url}}/webhooks/WEBHOOK_UUID",
3153+
"host": [
3154+
"{{url}}"
3155+
],
3156+
"path": [
3157+
"webhooks",
3158+
"WEBHOOK_UUID"
3159+
]
3160+
}
3161+
},
3162+
"response": []
3163+
}
3164+
]
3165+
},
30473166
{
30483167
"name": "Stats",
30493168
"item": [

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@
350350
"reference/api/experimental_features",
351351
"reference/api/metrics",
352352
"reference/api/logs",
353-
"reference/api/export"
353+
"reference/api/export",
354+
"reference/api/webhooks"
354355
]
355356
},
356357
{

learn/async/asynchronous_operations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Tasks always contain a field indicating the task's current `status`. This field
8383
- **`failed`**: a failure occurred when processing the task. No changes were made to the database
8484
- **`canceled`**: the task was canceled
8585

86-
`succeeded`, `failed`, and `canceled` tasks are finished tasks. Meilisearch keeps them in the task database but has finished processing these tasks. It is possible to [configure a webhook](/learn/self_hosted/configure_meilisearch_at_launch#task-webhook-url) to notify external services when a task is finished.
86+
`succeeded`, `failed`, and `canceled` tasks are finished tasks. Meilisearch keeps them in the task database but has finished processing these tasks. It is possible to [configure a webhook](/reference/api/webhooks) to notify external services when a task is finished.
8787

8888
`enqueued` and `processing` tasks are unfinished tasks. Meilisearch is either processing them or will do so in the future.
8989

learn/async/task_webhook.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ description: Learn how to use webhooks to react to changes in your Meilisearch d
55
sidebarDepth: 3
66
---
77

8-
This guide teaches you how to use webhooks to notify a URL when Meilisearch completed a [task](/learn/async/asynchronous_operations).
8+
This guide teaches you how to configure a single webhook via instance options to notify a URL when Meilisearch completes a [task](/learn/async/asynchronous_operations).
9+
10+
<Tip>
11+
If you are using Meilisearch Cloud or need to configure multiple webhooks, use the [`/webhooks` API route](/reference/api/webhooks) instead.
12+
</Tip>
913

1014
## Requirements
1115

learn/async/working_with_tasks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ This will return the full task object:
8686
}
8787
```
8888

89-
If the task is still `enqueued` or `processing`, wait a few moments and query the database once again. If you are working with a self-hosted Meilisearch instance, you may also [set up a webhook listener](/learn/async/task_webhook).
89+
If the task is still `enqueued` or `processing`, wait a few moments and query the database once again. You may also [set up a webhook listener](/reference/api/webhooks).
9090

9191
When `status` changes to `succeeded`, Meilisearch has finished processing your request.
9292

learn/resources/telemetry.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,5 @@ This list is liable to change with every new version of Meilisearch. It's not be
273273
| `export.avg_index_patterns` | Average number of index patterns set per export | `3.2`
274274
| `export.avg_patterns_with_filter` | Average number of index patterns with filters per export | `1.7`
275275
| `export.avg_payload_size` | Average payload size per export | `512`
276+
| `webhooks_created` | Number of webhooks created in an instance | `2`
277+
| `webhooks.updated` | Number of times all webhooks in an instance have been updated | `5`

learn/self_hosted/configure_meilisearch_at_launch.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ Notifies the configured URL whenever Meilisearch [finishes processing a task](/l
495495

496496
The webhook payload contains the list of finished tasks in [ndjson](https://github.com/ndjson/ndjson-spec). For more information, [consult the dedicated task webhook guide](/learn/async/task_webhook).
497497

498+
The task webhook option requires having access to a command-line interface. If you are using Meilisearch Cloud, use the [`/webhooks` API route](/reference/api/webhooks) instead.
499+
498500
### Task webhook authorization header
499501

500502
**Environment variable**: `MEILI_TASK_WEBHOOK_AUTHORIZATION_HEADER`<br />

reference/api/keys.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Custom API keys are deterministic: `key` is a SHA256 hash of the `uid` and maste
7878
**Default value**: N/A<br />
7979
**Description**: An array of API actions permitted for the key, represented as strings. API actions are only possible on authorized [`indexes`](#indexes). `["*"]` for all actions.
8080

81-
You can use `*` as a wildcard to access all endpoints for the `documents`, `indexes`, `tasks`, `settings`, `stats` and `dumps` actions. For example, `documents.*` gives access to all document actions.
81+
You can use `*` as a wildcard to access all endpoints for the `documents`, `indexes`, `tasks`, `settings`, `stats`, `webhooks`, and `dumps` actions. For example, `documents.*` gives access to all document actions.
8282

8383
<Warning>
8484
For security reasons, we do not recommend creating keys that can perform all actions.
@@ -111,6 +111,10 @@ For security reasons, we do not recommend creating keys that can perform all act
111111
| **`network.get`** | Provides access to the [get the network object](/reference/api/network#get-the-network-object) endpoint |
112112
| **`network.update`** | Provides access to the [update the network object](/reference/api/network#update-the-network-object) endpoint |
113113
| **`chatCompletions`** | Provides access to the [chat completions endpoints](/reference/api/chats). Requires experimental feature to be enabled |
114+
| **`webhooks.get`** | Provides access to the [get webhooks](/reference/api/webhooks#get-all-webhooks) endpoints |
115+
| **`webhooks.create`** | Provides access to the [create webhooks](/reference/api/webhooks#create-a-webhook) endpoint |
116+
| **`webhooks.update`** | Provides access to the [update webhooks](/reference/api/webhooks#update-a-webhook) endpoint |
117+
| **`webhooks.delete`** | Provides access to the [delete webhooks](/reference/api/webhooks#delete-a-webhook) endpoint |
114118

115119
### `indexes`
116120

0 commit comments

Comments
 (0)