Skip to content

Webhooks

Cosmic makes it easy to add Webhooks to trigger a POST request to the endpoint of your choice when an event occurs in your Bucket. This is great for integrating static site rebuilds whenever content is changed, or adding third-party integrations like notifying your team on Slack whenever content has been added.

Format

All requests to your endpoint are sent via POST with Header and Body information. For example:

Example Header

{
"content-length": "450", // Your content length
"x-cosmicjs-event": "object.edited.draft", // Your event key (see below)
"accept": "application/json",
"content-type": "application/json"
}

Example Body

{
"type": "object.edited.draft",
"created_at": 1576861549889,
"data": {
"_id": "5dfcff5d6340c9000865cc25",
"slug": "my-awesome-title",
"title": "My Awesome Title",
"content": "<p>My awesome content</p>",
"metafields": [],
"modified_at": "2019-12-20T17:05:49.879Z",
"modified_by": "56d66b2f903a79b904000001",
"type_slug": "tests",
"status": "draft",
"publish_at": null,
"bucket": "5df644188e47080008e7721a",
"created_at": "2019-12-20T17:05:49.879Z",
"created_by": "56d66b2f903a79b904000001",
"metadata": null
}
}

Payload limits

The payload limit is 6MB. You can disable the data payload or set comma-separated props to minimize the payload size. See props for more information. (Excludes delete events. Using props returns first level props only.)

Events

This is a list of available events. We will add to this list as more features become available.

EventOccurs When
object.created.draftObject created and set to draft.
object.created.publishedObject created and published.
object.edited.draftExisting Object edited and set to draft.
object.edited.publishedExisting Object edited and published.
object.edited.unpublishedExisting Object edited and unpublished.
object.deletedObject deleted.
media.createdMedia created.
media.editedMedia edited.
media.deletedMedia deleted.
merge.completedMerge Request completed.

Getting Started

Manage Webhooks in your Bucket by logging in and going to the Webhooks section in your Bucket located at:

  • Your Bucket Dashboard > Webhooks

Testing

Using a service like Beeceptor makes it easy to test your Webhooks and view response data.