> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://contentful.com/developers/docs/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful.com/_mcp/server. # Create a webhook POST https://api.contentful.com/spaces/{space_id}/webhook_definitions Content-Type: application/vnd.contentful.management.v1+json Reference: https://contentful.com/developers/docs/references/content-management-api/webhooks/create-a-webhook ## Authentication - `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer `, where token is your auth token. ## Request ### Path parameters - `space_id` (string, required) — ID of the space in form of a string ### Body (application/vnd.contentful.management.v1+json) This endpoint expects a map from string to any. - `map from string to any` ## Response ### 200 OK - Request successful - `map from string to any` ## Examples **Request** ```json { "active": true, "filters": [], "httpBasicPassword": "yolo", "httpBasicUsername": "yolo", "name": "My webhook", "topics": [ "Entry.create", "ContentType.create", "*.publish", "Asset.*" ], "url": "https://www.example.com/test" } ``` **Response** ```json { "active": true, "filters": [], "headers": [ { "key": "header1", "value": "value1" }, { "key": "header2", "value": "value2" } ], "httpBasicUsername": "yolo", "name": "My webhook", "sys": { "createdAt": "2025-01-12T11:06:22.000Z", "createdBy": { "sys": { "id": "7BslKh9TdKGOK41VmLDjFZ", "linkType": "User", "type": "Link" } }, "id": "0KzM2HxYr5O1pZ4SaUzK8h", "space": { "sys": { "id": "yadj1kx9rmg0", "linkType": "Space", "type": "Link" } }, "type": "WebhookDefinition", "updatedAt": "2025-01-12T11:06:22.000Z", "updatedBy": { "sys": { "id": "4FLrUHftHW3v2BLi9fzfjU", "linkType": "User", "type": "Link" } }, "version": 1 }, "topics": [ "Entry.create", "ContentType.create", "*.publish", "Asset.*" ], "url": "https://www.example.com" } ``` **SDK Code** ```android Android // Create the Contentful client. final CMAClient client = new CMAClient .Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build(); // Create a local webhook. final CMAWebhook webhook = new CMAWebhook() .setUrl("https://example.com"); // Send it to Contentful. client .webhooks() .async() .create( "", webhook, new CMACallback() { @Override protected void onSuccess(CMAWebhook result) { // Done, take a look at this `result` callback parameter. new AlertDialog.Builder(context) .setTitle("Contentful") .setMessage("Creating a new webhook was successful." + "\n\nResult: " + result) .show(); } @Override protected void onFailure(RuntimeException exception) { // An error occurred! Inform the user. new AlertDialog.Builder(context) .setTitle("Contentful Error") .setMessage("Could not create a webhook." + "\n\nReason: " + exception.toString()) .show(); super.onFailure(exception); } } ); ``` ```java Java // Create the Contentful client. final CMAClient client = new CMAClient .Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build(); // Create a local webhook. final CMAWebhook webhook = new CMAWebhook() .setUrl("https://example.com"); // Send it to Contentful. final CMAWebhook created = client .webhooks() .create("", webhook); ``` ```kotlin Kotlin // Create the Contentful client. val client = CMAClient.Builder() .setAccessToken("") .setSpaceId("") .setEnvironmentId("") .build() // Create a local webhook. val webhook = CMAWebhook() .setUrl("https://example.com") // Send it to Contentful. val created = client .webhooks() .create("", webhook) ``` ```swift Swift We currently don't provide a CMA SDK for this platform. ``` ```js-legacy JavaScript (legacy) import { createClient } from 'contentful-management' const client = createClient({ accessToken: '' }, { type: 'legacy' }) // Create webhook client.getSpace('') .then((space) => space.createWebhookWithId('', { 'name': 'My webhook', 'url': 'https://www.example.com/test', 'topics': [ 'Entry.create', 'ContentType.create', '*.publish', 'Asset.*' ] })) .then((webhook) => console.log(webhook)) .catch(console.error) ``` ```javascript JavaScript import { createClient } from 'contentful-management' // Client init const client = contentful.createClient({ accessToken: '' }) const webhook = await client.webhook.create( { spaceId: '', }, { name: 'My webhook', url: 'https://www.example.com/test', topics: ['Entry.create', 'ContentType.create', '*.publish', 'Asset.*'], } ); ``` ```php PHP $client = new \Contentful\Management\Client(''); $space = $client->getSpaceProxy(''); $webhook = new \Contentful\Management\Resource\Webhook( 'My webhook', 'https://www.example.com/test' ); $webhook->setTopics(['Entry.create', 'ContentType.create']) ->setHeaders(['X-Test-Header' => 'Test Value']) ->setHttpBasicUsername('username') ->setHttpBasicPassword('password'); $space->create($webhook); ``` ```ruby Ruby require 'contentful/management' client = Contentful::Management::Client.new('') webhook = client.webhooks('').create( name: 'My Webhook', url: 'https://www.example.com', httpBasicUsername: 'username', httpBasicPassword: 'password' ) ``` ```python Python from contentful_management import Client client = Client('') webhook = client.webhooks('').create({ 'name': 'My Webhook', 'url': 'https://www.example.com', 'httpBasicUsername': 'username', 'httpBasicPassword': 'password' }) ``` ```.net .NET // This client should only be created once per application. var httpClient = new HttpClient(); var client = new ContentfulManagementClient(httpClient, "", ""); var webhook = new Webhook(); webhook.SystemProperties = new SystemProperties(); webhook.SystemProperties.Id = "hook-id"; webhook.Name = "New product"; webhook.Url = "https://www.example.com/"; // Webhook target. webhook.HttpBasicPassword = "Pass"; webhook.HttpBasicUsername = "User"; webhook.Headers = new List>(); // Send custom key-value pairs in the headers. webhook.Headers.Add(new KeyValuePair("custom", "header")); // Add a header with name "custom" and value "header". webhook.Topics = new List() // Topics are the events that trigger this webhook. { "Entry.*" }; await client.CreateOrUpdateWebhook(webhook); ```