|
| 1 | +--- |
| 2 | +title: Webhooks |
| 3 | +description: Use the /webhooks to trigger automatic workflows when Meilisearch finishes processing tasks. |
| 4 | +--- |
| 5 | + |
| 6 | +import { RouteHighlighter } from '/snippets/route_highlighter.mdx' |
| 7 | + |
| 8 | +import CodeSamplesWebhooksGet1 from '/snippets/samples/code_samples_webhooks_get_1.mdx'; |
| 9 | +import CodeSamplesWebhooksPost1 from '/snippets/samples/code_samples_webhooks_post_1.mdx'; |
| 10 | +import CodeSamplesWebhooksPatch1 from '/snippets/samples/code_samples_webhooks_patch_1.mdx'; |
| 11 | +import CodeSamplesWebhooksDelete1 from '/snippets/samples/code_samples_webhooks_delete_1.mdx'; |
| 12 | + |
| 13 | +Use the `/webhooks` to trigger automatic workflows when Meilisearch finishes processing tasks. |
| 14 | + |
| 15 | +## The webhook object |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "uuid": "V4_UUID_GENERATED_BY_MEILISEARCH", |
| 20 | + "url": "WEBHOOK_NOTIFICATION_TARGET_URL", |
| 21 | + "headers": { |
| 22 | + "HEADER": "VALUE", |
| 23 | + }, |
| 24 | + "isEditable": false |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +- `uuid`: a v4 uuid Meilisearch automatically generates when you create a new webhook |
| 29 | +- `url`: a string indication the URL Meilisearch should notify whenever it completes a task, required |
| 30 | +- `headers`: an object with HTTP headers and their values, optional, often used for authentication |
| 31 | +- `isEditable`: read-only Boolean field indicating whether you can edit the webhook. Meilisearch automatically sets this to false for its internal webhooks |
| 32 | + |
| 33 | +## The webhook payload |
| 34 | + |
| 35 | +When Meilisearch finishes processing a task, it sends the relevant [task object](/reference/api/tasks#task-object) to all configured webhooks. |
| 36 | + |
| 37 | +## Get all webhooks |
| 38 | + |
| 39 | +<RouteHighlighter method="GET" path="/healths" /> |
| 40 | + |
| 41 | +Get a list of all webhooks configured in the current Meilisearch instance. |
| 42 | + |
| 43 | +### Example |
| 44 | + |
| 45 | +<CodeSamplesWebhooksGet1 /> |
| 46 | + |
| 47 | +#### Response: `200 OK` |
| 48 | + |
| 49 | +```json |
| 50 | +{ |
| 51 | + "results": [ |
| 52 | + { |
| 53 | + "uuid": "UUID_V4", |
| 54 | + "url": "WEBHOOK_TARGET_URL", |
| 55 | + "headers": { |
| 56 | + "HEADER": "VALUE", |
| 57 | + }, |
| 58 | + "isEditable": false |
| 59 | + }, |
| 60 | + { |
| 61 | + "uuid": "UUID_V4", |
| 62 | + "url": "WEBHOOK_TARGET_URL", |
| 63 | + "headers": null, |
| 64 | + "isEditable": true |
| 65 | + } |
| 66 | + ] |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Create new webhook |
| 71 | + |
| 72 | +<RouteHighlighter method="POST" path="/webhooks" /> |
| 73 | + |
| 74 | +Create a new webhook. When Meilisearch finishes processing a task, it sends the relevant [task object](/reference/api/tasks#task-object) to all configured webhooks. |
| 75 | + |
| 76 | +### Example |
| 77 | + |
| 78 | +<CodeSamplesWebhooksPost1 /> |
| 79 | + |
| 80 | +#### Response: `200 OK` |
| 81 | + |
| 82 | +```json |
| 83 | +{ |
| 84 | + "uuid": "627ea538-733d-4545-8d2d-03526eb381ce", |
| 85 | + "url": "WEBHOOK_TARGET_URL", |
| 86 | + "headers": { |
| 87 | + "authorization": "SECURITY_KEY", |
| 88 | + "referer": "https://example.com", |
| 89 | + }, |
| 90 | + "isEditable": true |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Update webhook |
| 95 | + |
| 96 | +<RouteHighlighter method="PATCH" path="/webhooks/{uuid}" /> |
| 97 | + |
| 98 | +Update the configuration for the specified webhook. To remove a field, set its value to `null`. |
| 99 | + |
| 100 | +<Note> |
| 101 | +It is not possible to edit webhooks whose `isEditable` field is set to `false`. |
| 102 | + |
| 103 | +Meilisearch Cloud may create internal webhooks to support features such as Analytics and monitoring. These webhooks are always `isEditable: false`. |
| 104 | +</Note> |
| 105 | + |
| 106 | +### Example |
| 107 | + |
| 108 | +<CodeSamplesWebhooksPatch1 /> |
| 109 | + |
| 110 | +#### Response: `200 OK` |
| 111 | + |
| 112 | +```json |
| 113 | +{ |
| 114 | + "uuid": "627ea538-733d-4545-8d2d-03526eb381ce", |
| 115 | + "url": "WEBHOOK_TARGET_URL", |
| 116 | + "headers": { |
| 117 | + "authorization": "SECURITY_KEY" |
| 118 | + }, |
| 119 | + "isEditable": true |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +## Delete webhook |
| 124 | + |
| 125 | +<RouteHighlighter method="DELETE" path="/webhooks/{uuid}" /> |
| 126 | + |
| 127 | +Delete a webhook and stop sending task completion data to the target URL. |
| 128 | + |
| 129 | +<Note> |
| 130 | +It is not possible to delete webhooks whose `isEditable` field is set to `false`. |
| 131 | +</Note> |
| 132 | + |
| 133 | +### Example |
| 134 | + |
| 135 | +<CodeSamplesWebhooksDelete1 /> |
| 136 | + |
| 137 | +#### Response: `204 No Content` |
0 commit comments