| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | # Webhooks
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## What is a webhook
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | A webhook is a way for an application to notify other applications that an event occurred. | 
					
						
							| 
									
										
										
										
											2020-02-08 19:45:35 +01:00
										 |  |  | Using a webhook is a good way to tell third party providers to start some processing (CI, build, deployment ...). | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | The way a webhook works is by delivering information to a receiving application through HTTP requests (typically POST requests). | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## How to use
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | To access the webhook configuration panel, go to `Settings` > `Webhooks`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | ### Create a webhook
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | Click on `Add new webhook` and fill in the form. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Trigger a webhook
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-08 19:45:35 +01:00
										 |  |  | You can test out a webhook with a test event: `trigger-test`. Open the webhook you want to trigger. | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Click on the `Trigger` button. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You will see the trigger request appear and get the result. | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-08 19:45:35 +01:00
										 |  |  | ### Enable or disable a webhook
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-08 19:45:35 +01:00
										 |  |  | You can enable or disable a webhook from the list view directly. | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### Update a webhook
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | You can edit any webhook by clicking on the `pen` icon in the webhook list view. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | ### Delete a webhook
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 18:01:01 +01:00
										 |  |  | You can delete a webhook by clicking on the `trash` icon. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | ## Available events
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | By default Strapi webhooks can be triggered by the following events: | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 15:22:36 +01:00
										 |  |  | | Name           | Description                                     | | 
					
						
							|  |  |  | | -------------- | ----------------------------------------------- | | 
					
						
							|  |  |  | | `entry.create` | Triggered when a Content Type entry is created. | | 
					
						
							|  |  |  | | `entry.update` | Triggered when a Content Type entry is updated. | | 
					
						
							|  |  |  | | `entry.delete` | Triggered when a Content Type entry is deleted. | | 
					
						
							|  |  |  | | `media.create` | Triggered when a media is created.              | | 
					
						
							|  |  |  | | `media.delete` | Triggered when a media is deleted.              | | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Payloads
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### Headers
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | When a payload is delivered to your webhook's URL, it will contain specific headers: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | | Header           | Description                                | | 
					
						
							|  |  |  | | ---------------- | ------------------------------------------ | | 
					
						
							|  |  |  | | `X-Strapi-Event` | Name of the event type that was triggered. | | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | ### `entry.create`
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | This event is triggered when a new entry is created. | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | **Example payload** | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "event": "entry.create", | 
					
						
							|  |  |  |   "created_at": "2020-01-10T08:47:36.649Z", | 
					
						
							|  |  |  |   "model": "address", | 
					
						
							|  |  |  |   "entry": { | 
					
						
							|  |  |  |     "id": 1, | 
					
						
							|  |  |  |     "geolocation": {}, | 
					
						
							|  |  |  |     "city": "Paris", | 
					
						
							|  |  |  |     "postal_code": null, | 
					
						
							|  |  |  |     "category": null, | 
					
						
							|  |  |  |     "full_name": "Paris", | 
					
						
							|  |  |  |     "created_at": "2020-01-10T08:47:36.264Z", | 
					
						
							|  |  |  |     "updated_at": "2020-01-10T08:47:36.264Z", | 
					
						
							|  |  |  |     "cover": null, | 
					
						
							|  |  |  |     "images": [] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | ### `entry.update`
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | This event is triggered when an entry is updated. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **Example payload** | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "event": "entry.update", | 
					
						
							|  |  |  |   "created_at": "2020-01-10T08:58:26.563Z", | 
					
						
							|  |  |  |   "model": "address", | 
					
						
							|  |  |  |   "entry": { | 
					
						
							|  |  |  |     "id": 1, | 
					
						
							|  |  |  |     "geolocation": {}, | 
					
						
							|  |  |  |     "city": "Paris", | 
					
						
							|  |  |  |     "postal_code": null, | 
					
						
							|  |  |  |     "category": null, | 
					
						
							|  |  |  |     "full_name": "Paris", | 
					
						
							|  |  |  |     "created_at": "2020-01-10T08:47:36.264Z", | 
					
						
							|  |  |  |     "updated_at": "2020-01-10T08:58:26.210Z", | 
					
						
							|  |  |  |     "cover": null, | 
					
						
							|  |  |  |     "images": [] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | ### `entry.delete`
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | This event is triggered when an entry is deleted. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **Example payload** | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "event": "entry.delete", | 
					
						
							|  |  |  |   "created_at": "2020-01-10T08:59:35.796Z", | 
					
						
							|  |  |  |   "model": "address", | 
					
						
							|  |  |  |   "entry": { | 
					
						
							|  |  |  |     "id": 1, | 
					
						
							|  |  |  |     "geolocation": {}, | 
					
						
							|  |  |  |     "city": "Paris", | 
					
						
							|  |  |  |     "postal_code": null, | 
					
						
							|  |  |  |     "category": null, | 
					
						
							|  |  |  |     "full_name": "Paris", | 
					
						
							|  |  |  |     "created_at": "2020-01-10T08:47:36.264Z", | 
					
						
							|  |  |  |     "updated_at": "2020-01-10T08:58:26.210Z", | 
					
						
							|  |  |  |     "cover": null, | 
					
						
							|  |  |  |     "images": [] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | ### `media.create`
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | This event is triggered when you upload a file on entry creation or through the media interface. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | **Example payload** | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "event": "media.create", | 
					
						
							|  |  |  |   "created_at": "2020-01-10T10:58:41.115Z", | 
					
						
							|  |  |  |   "media": { | 
					
						
							|  |  |  |     "id": 1, | 
					
						
							|  |  |  |     "name": "image.png", | 
					
						
							|  |  |  |     "hash": "353fc98a19e44da9acf61d71b11895f9", | 
					
						
							|  |  |  |     "sha256": "huGUaFJhmcZRHLcxeQNKblh53vtSUXYaB16WSOe0Bdc", | 
					
						
							|  |  |  |     "ext": ".png", | 
					
						
							|  |  |  |     "mime": "image/png", | 
					
						
							|  |  |  |     "size": 228.19, | 
					
						
							|  |  |  |     "url": "/uploads/353fc98a19e44da9acf61d71b11895f9.png", | 
					
						
							|  |  |  |     "provider": "local", | 
					
						
							|  |  |  |     "provider_metadata": null, | 
					
						
							|  |  |  |     "created_at": "2020-01-10T10:58:41.095Z", | 
					
						
							|  |  |  |     "updated_at": "2020-01-10T10:58:41.095Z", | 
					
						
							|  |  |  |     "related": [] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | ### `media.delete`
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | This event is triggered only when you delete a media through the media interface. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | **Example payload** | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "event": "media.delete", | 
					
						
							|  |  |  |   "created_at": "2020-01-10T11:02:46.232Z", | 
					
						
							|  |  |  |   "media": { | 
					
						
							|  |  |  |     "id": 11, | 
					
						
							|  |  |  |     "name": "photo.png", | 
					
						
							|  |  |  |     "hash": "43761478513a4c47a5fd4a03178cfccb", | 
					
						
							|  |  |  |     "sha256": "HrpDOKLFoSocilA6B0_icA9XXTSPR9heekt2SsHTZZE", | 
					
						
							|  |  |  |     "ext": ".png", | 
					
						
							|  |  |  |     "mime": "image/png", | 
					
						
							|  |  |  |     "size": 4947.76, | 
					
						
							|  |  |  |     "url": "/uploads/43761478513a4c47a5fd4a03178cfccb.png", | 
					
						
							|  |  |  |     "provider": "local", | 
					
						
							|  |  |  |     "provider_metadata": null, | 
					
						
							|  |  |  |     "created_at": "2020-01-07T19:34:32.168Z", | 
					
						
							|  |  |  |     "updated_at": "2020-01-07T19:34:32.168Z", | 
					
						
							|  |  |  |     "related": [] | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | ## Developer documentation
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:06:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | ### Available configurations
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:47:47 +02:00
										 |  |  | You can set webhook configurations inside the file `./config/server.js`. | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | - `webhooks` | 
					
						
							|  |  |  |   - `defaultHeaders`: You can set default headers to use for your webhook requests. This option is overwritten by the headers set in the webhook itself. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | **Example configuration** | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:47:47 +02:00
										 |  |  | ```js | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   webhooks: { | 
					
						
							|  |  |  |     defaultHeaders: { | 
					
						
							|  |  |  |       'Custom-Header': 'my-custom-header', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | ### Securing your webhooks
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 11:57:49 +01:00
										 |  |  | Most of the time, webhooks make requests to public URLs, therefore it is possible that someone may find that URL and send it wrong information. | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | To prevent this from happening you can send a header with an authentication token. Using the Admin panel you would have to do it for every webhook. | 
					
						
							|  |  |  | Another way is to define `defaultHeaders` to add to every webhook requests. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:47:47 +02:00
										 |  |  | You can configure these global headers by updating the file at `./config/server.js`: | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | :::: tabs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ::: tab "Simple token" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:47:47 +02:00
										 |  |  | ```js | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   webhooks: { | 
					
						
							|  |  |  |     defaultHeaders: { | 
					
						
							|  |  |  |       Authorization: 'Bearer my-very-secured-token', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ::: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ::: tab "Environment variable" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-10 15:47:47 +02:00
										 |  |  | ```js | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   webhooks: { | 
					
						
							|  |  |  |     defaultHeaders: { | 
					
						
							|  |  |  |       Authorization: `Bearer ${process.env.WEBHOOK_TOKEN}`, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-10 12:24:34 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :::: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 14:20:55 +01:00
										 |  |  | If you are developing the webhook handler yourself you can now verify the token by reading the headers. |