Webhook
Webhook
A webhook is a mechanism that sends real-time information to any third-party app or service to keep your application in sync with your Contentstack account. Webhooks allow you to specify a URL to which you would like Contentstack to post data when an event happens.
update
The Update Webhook call lets you update the name and description of an existing Webhook.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.fetch()
.then((webhook) => {
webhook.title = 'My New Webhook'
webhook.description = 'Webhook description'
return webhook.update()
})
.then((webhook) => console.log(webhook))delete
The Delete Webhook call is used to delete an existing Webhook permanently from your Stack.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.delete()
.then((response) => console.log(response.notice))fetch
The fetch Webhook call fetches Webhook details.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.fetch()
.then((webhook) => console.log(webhook))executions
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.executions()
.then((webhook) => console.log(webhook))retry
The retry webhook execution will perform retry execution.
| Name | Type | Description |
|---|---|---|
| executionUid | string | execution UID that you receive when you execute the 'Get executions of webhooks' call. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
.retry( executionUid )
.then((webhook) => console.log(webhook))create
The Create a webhook request allows you to create a new webhook in a specific stack.
| Name | Type | Description |
|---|---|---|
| params.webhook | object | The webhook details including name, destinations, channels, and retry policy. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const webhook = {
name: 'Test',
destinations: [{
target_url: 'http://example.com',
http_basic_auth: 'basic',
http_basic_password: 'test',
custom_header: [{
header_name: 'Custom',
value: 'testing'
}]
}],
channels: [
'assets.create'
],
retry_policy: 'manual',
disabled: false
}
client.stack({ api_key: 'api_key'}).webhook()
.create({ webhook })
.then((webhook) => console.log(webhook))fetchAll
The Get all Webhook call lists all Webhooks from Stack.
| Name | Type | Description |
|---|---|---|
| params.include_count | boolean | The `include_count’ parameter includes the count of total number of webhook in your stack, along with the details of each webhook. |
| params.limit | number | The ‘limit’ parameter will return a specific number of webhook in the output. |
| params.skip | number | The ‘skip’ parameter will skip a specific number of webhook in the response. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook()
.fetchAll()
.then((webhook) => console.log(webhook))import
The Import a webhook call imports a web hook into a stack.
| Name | Type | Description |
|---|---|---|
| params.webhook (required) | string | File path to import webhook |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
webhook: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).webhook().import(data)
.then((webhook) => console.log(webhook))
//OR
client.stack({ api_key: 'api_key'}).webhook('webhook_uid').import(data)
.then((webhook) => console.log(webhook))