> 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/developers/docs/_mcp/server.

# Create or update a webhook

PUT https://api.contentful.com/spaces/{space_id}/webhook_definitions/{webhook_definition_id}
Content-Type: application/vnd.contentful.management.v1+json

Reference: https://contentful.com/developers/docs/references/content-management-api/webhooks/create-or-update-a-webhook

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `space_id` (string, required) — ID of the space in form of a string
- `webhook_definition_id` (string, required) — ID of the webhook 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": [],
  "headers": [
    {
      "key": "header1",
      "value": "value1"
    },
    {
      "key": "header2",
      "value": "value2"
    }
  ],
  "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-03-14T10:32:38.000Z",
    "createdBy": {
      "sys": {
        "id": "7BslKh9TdKGOK41VmLDjFZ",
        "linkType": "User",
        "type": "Link"
      }
    },
    "id": "0KzM2HxYr5O1pZ4SaUzK8h",
    "space": {
      "sys": {
        "id": "yadj1kx9rmg0",
        "linkType": "Space",
        "type": "Link"
      }
    },
    "type": "WebhookDefinition",
    "updatedAt": "2025-03-14T10:32:38.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("<access_token>")
        .setSpaceId("<space_id>")
        .setEnvironmentId("<environment_id>")
        .build();

client
    .webhooks()
    .async()
    .fetchOne(
        "<space_id>",
        "<webhook_id>",
        new CMACallback<CMAWebhook>() {
          @Override protected void onSuccess(CMAWebhook webhook) {
            // Change the asset.
            webhook.setUrl("http://example.com");

            client
                .webhooks()
                .async()
                .update(
                    webhook,
                    new CMACallback<CMAWebhook>() {
                      @Override protected void onSuccess(CMAWebhook result) {
                        // Done, your updated webhook will be the parameter of this callback.
                        new AlertDialog.Builder(context)
                            .setTitle("Contentful")
                            .setMessage("Updating the 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 update that webhook." +
                                "\n\nReason: " + exception.toString())
                            .show();

                        super.onFailure(exception);
                      }
                    }
                );
          }

          @Override protected void onFailure(RuntimeException exception) {
            // An error occurred! Inform the user.
            new AlertDialog.Builder(context)
                .setTitle("Contentful Error")
                .setMessage("Could not fetch the webhook." +
                    "\n\nReason: " + exception.toString())
                .show();

            super.onFailure(exception);
          }
        }
    );
```

```java Java
// Create the Contentful client.
final CMAClient client =
    new CMAClient
        .Builder()
        .setAccessToken("<access_token>")
        .setSpaceId("<space_id>")
        .setEnvironmentId("<environment_id>")
        .build();

// Fetch a webhook first.
final CMAWebhook webhook =
    client
        .webhooks()
        .fetchOne(
            "<space_id>",
            "<webhook_id>");

// Change something about it.
webhook.setUrl("https://example.com");

// Update it on Contentful.
final CMAWebhook update =
    client
        .webhooks()
        .update(webhook);
```

```kotlin Kotlin
// Create the Contentful client.
val client = CMAClient.Builder()
    .setAccessToken("<access_token>")
    .setSpaceId("<space_id>")
    .setEnvironmentId("<environment_id>")
    .build()

// Fetch a webhook first.
val webhook = client
        .webhooks()
        .fetchOne(
                "<space_id>",
                "<webhook_id>")

// Change something about it.
webhook.url = "https://example.com"

// Update it on Contentful.
val update = client
        .webhooks()
        .update(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: '<content_management_api_key>'
}, { type: 'legacy' })

// Create webhook
client.getSpace('<space_id>')
.then((space) => space.createWebhookWithId('<webhook_id>', {
  'name': 'My webhook',
  'url': 'https://www.example.com/test',
  'topics': [
    'Entry.create',
    'ContentType.create',
    '*.publish',
    'Asset.*'
  ]
}))
.then((webhook) => console.log(webhook))
.catch(console.error)

// Update webhook
client.getSpace('<space_id>')
.then((space) => space.getWebhook('<webhook_id>'))
.then((webhook) => {
  webhook.name = 'New webhook name'
  return webhook.update()
})
.then((webhook) => console.log(`Webhook ${webhook.sys.id} updated.`))
.catch(console.error)
```

```javascript JavaScript
import { createClient } from 'contentful-management'

// Client init
const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

const payload = {
  name: 'My webhook',
  url: 'https://www.example.com/test',
  topics: ['Entry.create', 'ContentType.create', '*.publish', 'Asset.*'],
};

// Create webhook
const webhook = await client.webhook.create(
  {
    spaceId: '<space_id>',
  },
  payload
);

// Update webhook
const updatedWebhook = await client.webhook.update(
  {
    spaceId: '<space_id>',
    webhookDefinitionId: '<webhook_definition_id>',
  },
  {
    ...payload,
    name: 'New webhook name',
  }
);
```

```php PHP
$client = new \Contentful\Management\Client('<content_management_api_key>');

$space = $client->getSpaceProxy('<space_id>');

$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);

$webhook->setName('New webhook name');
$webhook->update();
```

```ruby Ruby
require 'contentful/management'

client = Contentful::Management::Client.new('<content_management_api_key>')

# Create a webhook:
webhook = client.webhooks('<space_id>').create(
  name: 'My Webhook',
  url: 'https://www.example.com',
  httpBasicUsername: 'username',
  httpBasicPassword: 'password'
)

# Update a webhook:
webhook.name = 'New webhook name'
webhook.save
```

```python Python
from contentful_management import Client

client = Client('<content_management_api_key>')

# Create a webhook:
webhook = client.webhooks('<space_id>').create({
    'name': 'My Webhook',
    'url': 'https://www.example.com',
    'httpBasicUsername': 'username',
    'httpBasicPassword': 'password'
})

# Update a webhook:
webhook.name = 'New webhook name'
webhook.save()
```

```.net .NET
// This client should only be created once per application.
var httpClient = new HttpClient();

var client = new ContentfulManagementClient(httpClient, "<content_management_api_key>", "<space_id>");

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<KeyValuePair<string, string>>(); // Send custom key-value pairs in the headers.
webhook.Headers.Add(new KeyValuePair<string, string>("custom", "header")); // Add a header with name "custom" and value "header".
webhook.Topics = new List<string>() // Topics are the events that trigger this webhook.
{
    "Entry.*"
};

await client.CreateOrUpdateWebhook(webhook);
```