Webhook

View as Markdown

Webhook

A webhook sends data to a URL that you choose when an event happens in a stack, such as an entry publish. It keeps a third-party app or service in sync with your content. The Webhook class manages the webhooks of one stack through the Content Management API (CMA). Use this class to

  • list, create, read, update and delete webhooks
  • import a webhook from a JSON file, as a new webhook or over an existing one
  • read the executions of a webhook and retry one of them

Call the webhook method of the Stack class to get an object.

Instance State

  • Call stack.webhook() without a UID to work with the collection, for example create and fetchAll.
  • Call stack.webhook('<WEBHOOK_UID>') to work with one webhook, for example fetch and executions.
  • import exists on both forms. On stack.webhook() it creates a new webhook, and on stack.webhook('<WEBHOOK_UID>') it updates that webhook from the file.
  • Each form has only its own request methods. fetch is undefined on stack.webhook(), and create is undefined on stack.webhook('<WEBHOOK_UID>'), so calling the wrong one throws TypeError.

Warning stack.webhook('') returns the collection form, because the SDK treats an empty string as no UID. On that form, import creates a new webhook instead of updating one. Check the UID before you build the object.

Class-Level Notes

Headers.

Rate limiting and retry.

  • This SDK automatically retries on 429 with configurable delay and attempt limits. That retry is separate from retry, which asks the API to run a webhook execution again.

Additional Resource For more information on the retry options and their defaults, refer to the Contentstack documentation.

Capability Matrix

CapabilitySupportedNotes / Alternative
Export a webhook as a JSON fileNoThe SDK has no export method. Use fetch and save the fields
Read the execution log of a webhookNoexecutions returns the details of each execution
Import a webhook in a browserNoimport reads the file from disk, so it runs in Node.js only

Method Index

Work with the collection. Available on stack.webhook().

Method NameReturnsDescription
createThe new webhook.Creates a webhook in the stack.
fetchAllThe webhooks of the stack.Lists every webhook of the stack.

Work with one webhook. Available on stack.webhook('<WEBHOOK_UID>').

Method NameReturnsDescription
fetchThe requested webhook.Retrieves one webhook.
updateThe updated webhook.Saves changes to one webhook.
deleteThe API response with a notice.Deletes one webhook.
executionsThe executions of the webhook.Lists the executions of one webhook.
retryThe API response for the retry.Runs a webhook execution again.

Import from a file. Available on stack.webhook() and stack.webhook('<WEBHOOK_UID>').

Method NameReturnsDescription
importThe imported webhook.Imports a webhook from a JSON file.

Set request headers. Available on both forms.

Method NameReturnsDescription
addHeaderThe same webhook object, for chaining.Adds one request header.
addHeaderDictThe same webhook object, for chaining.Adds several request headers.
removeHeaderThe same webhook object, for chaining.Removes one request header.

Class-Level Snippet

The snippet below lists the failed executions of a webhook in a date range and retries each one.

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })
const webhook = stack.webhook('<WEBHOOK_UID>')

try {
  const response = await webhook.executions({
    from: '2026-11-01T00:00:00.000Z',
    to: '2026-11-16T23:59:59.999Z',
    query: { status: { $gte: '400', $lte: '599' } }
  })
  for (const execution of response.webhooks) {
    const result = await webhook.retry(execution.uid)
    console.log(execution.uid, result)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

Methods

Each method of the Webhook class has its own section below, with its parameters, validation rules, behavior, and examples.

addHeader

addHeader adds one header to every request that this webhook object sends.

NameTypeDescription
key (required)string

Header name, for example x-request-id.

Default: Not applicable
value (required)string

Header value to send.

Default: Not applicable

Returns: Webhook. The same webhook object, for chaining.

Validation

  • There is no client-side validation. A null or undefined key leaves the headers unchanged, and addHeader returns the same object.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. addHeader sends no request.
  • The first header change on this object copies the headers that it inherited from the stack. The change then applies to this object only, not to the stack or to other objects that the same stack creates.
  • Every request method of this object sends its headers. The objects that those methods return carry the same headers.
  • A key that the object already holds gets the new value.

Example

Basic usage: tag the requests of one webhook object

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const webhook = stack.webhook('<WEBHOOK_UID>').addHeader('x-request-id', 'docs-123')
// Every request this object sends from now on carries the header
console.log(webhook.stackHeaders['x-request-id'])

addHeaderDict

addHeaderDict adds several headers at once to every request that this webhook object sends.

NameTypeDescription
headerDict (required)object

Header names and values to add.

Default: Not applicable

Returns: Webhook. The same webhook object, for chaining.

Validation

  • There is no client-side validation. A null value, or a value that is not an object, leaves the headers unchanged, and addHeaderDict returns the same object.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. addHeaderDict sends no request.
  • The first header change on this object copies the headers that it inherited from the stack. The change then applies to this object only, not to the stack or to other objects that the same stack creates.
  • Every request method of this object sends its headers. The objects that those methods return carry the same headers.
  • addHeaderDict merges headerDict into the headers of the object. A key that the object already holds gets the new value.

Example

Basic usage: add two tracing headers

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const webhook = stack.webhook().addHeaderDict({
  'x-request-id': 'docs-123',
  'x-trace-id': 'trace-456'
})
console.log(webhook.stackHeaders['x-request-id'], webhook.stackHeaders['x-trace-id'])

create

create adds a new webhook to the stack.

NameTypeDescription
data (required){ webhook: WebhookData }

Request body, with the webhook under the webhook key.

Default: Not applicable
data.webhook.name (required)string

Display name of the webhook.

Default: Not applicable
data.webhook.destinations (required)WebhookDestination[]

Target URLs, with optional authentication and custom headers.

Default: Not applicable
data.webhook.channels (required)string[]

Events that trigger the webhook, for example assets.create.

Default: Not applicable
data.webhook.retry_policystring

Retry policy for failed calls, for example manual.

Default: API default
data.webhook.disabledboolean

Set to true to create the webhook turned off.

Default: API default
data.webhook.concise_payloadboolean

Set to true to send a short JSON payload.

Default: API default
paramobject

Query parameters, sent as given.

Default: undefined (sends no extra query parameters)

Returns: Promise<Webhook>. The new webhook.

Validation

  • There is no client-side validation. create sends data as given and does not check its keys.
  • create exists only on stack.webhook(). On stack.webhook('<WEBHOOK_UID>') it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends POST /v3/webhooks with data as the JSON body, as Create a webhook describes.
  • The SDK does not wrap data. Put the webhook under the webhook key yourself.
  • Each entry of destinations holds a target_url, and optionally http_basic_auth, http_basic_password and a custom_header array of { header_name, value } objects.
  • Resolves to a Webhook object that the SDK builds from the webhook key of the response, with fetch, update, delete, executions and retry.

Example

Basic usage: create a webhook for entry changes

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const data = {
  webhook: {
    name: 'docs-test-entry-sync',
    destinations: [{ target_url: 'https://example.com/webhook-handler' }],
    channels: ['content_types.entries.create', 'content_types.entries.update']
  }
}

try {
  const webhook = await stack.webhook().create(data)
  console.log(webhook.uid, webhook.name)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: create a disabled webhook with authentication and a custom header

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const data = {
  webhook: {
    name: 'docs-test-asset-sync',
    destinations: [
      {
        target_url: 'https://example.com/webhook-handler',
        http_basic_auth: 'webhook_user',
        http_basic_password: 'webhook_password',
        custom_header: [{ header_name: 'X-Source', value: 'contentstack' }]
      }
    ],
    channels: ['assets.create', 'assets.update', 'assets.delete'],
    retry_policy: 'manual',
    disabled: true,
    concise_payload: true
  }
}
// Query parameters to send with the request
const param = {}

try {
  const webhook = await stack.webhook().create(data, param)
  console.log(webhook.uid, webhook.disabled)
} catch (error) {
  console.error(error.errorMessage)
}

delete

delete removes the webhook whose UID you passed to stack.webhook('<WEBHOOK_UID>') from the stack.

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}

Returns: Promise<Response>. The API response with a notice.

Warning A successful delete removes the webhook and stops its calls to the target URL, and you cannot undo it. Call fetch first to keep a copy of its settings.

Validation

  • There is no client-side validation.
  • delete exists only on stack.webhook('<WEBHOOK_UID>') and on the Webhook objects that fetch, create, fetchAll and import return. On stack.webhook() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends DELETE /v3/webhooks/{webhook_uid} with every key of param as a query parameter, as Delete webhook describes.
  • Resolves to the response body, which carries notice. When the API answers with an empty body, it resolves to { status, statusText } instead.
  • To stop the calls but keep the webhook, set disabled to true with update instead.

Example

Basic usage: delete one webhook

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.webhook('<WEBHOOK_UID>').delete()
  console.log(response.notice)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: pass query parameters with the request

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

// Query parameters to send with the request
const param = {}

try {
  const response = await stack.webhook('<WEBHOOK_UID>').delete(param)
  console.log(response.notice)
} catch (error) {
  console.error(error.errorMessage)
}

executions

executions retrieves the executions of the webhook whose UID you passed to stack.webhook('<WEBHOOK_UID>'). Each execution records one call from the webhook to its target URL.

NameTypeDescription
paramsobject

Query parameters, sent as given.

Default: undefined (sends no query parameters)
params.fromstring

Start of the date range, as an ISO date.

Default: API default
params.tostring

End of the date range, as an ISO date.

Default: API default
params.queryobject

Condition on status, sent as JSON.

Default: API default
params.only_eventsboolean

Set to true to leave out the request details.

Default: API default

Returns: Promise<object>. The executions of the webhook.

Validation

  • There is no client-side validation.
  • executions exists only on stack.webhook('<WEBHOOK_UID>') and on the Webhook objects that fetch, create, fetchAll and import return. On stack.webhook() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends GET /v3/webhooks/{webhook_uid}/executions with every key of params as a query parameter, as Get executions of a webhook describes.
  • Pass params.query as an object, for example { status: { $gte: '400', $lte: '599' } } for failed executions. The SDK converts it to JSON, so a JSON string value ends up encoded twice.
  • Resolves to the response body as a plain object. The executions sit under the webhooks key, and each one carries a uid, a status and a channel.
  • The API returns execution data for the last 30 days only.
  • Pass the uid of an execution to retry to run it again.

Example

Basic usage: list the executions of a webhook

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.webhook('<WEBHOOK_UID>').executions()
  for (const execution of response.webhooks) {
    console.log(execution.uid, execution.status, execution.channel)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: list the successful executions in a date range, without request details

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.webhook('<WEBHOOK_UID>').executions({
    from: '2026-11-01T00:00:00.000Z',
    to: '2026-11-16T23:59:59.999Z',
    query: { status: { $gte: '200', $lte: '399' } },
    only_events: true
  })
  console.log(response.webhooks.length)
} catch (error) {
  console.error(error.errorMessage)
}

fetch

fetch retrieves the webhook whose UID you passed to stack.webhook('<WEBHOOK_UID>').

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}

Returns: Promise<Webhook>. The requested webhook.

Validation

  • There is no client-side validation.
  • fetch exists only on stack.webhook('<WEBHOOK_UID>'). On stack.webhook() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends GET /v3/webhooks/{webhook_uid} with every key of param as a query parameter, as Get webhook describes.
  • Resolves to a new Webhook object that holds the webhook fields, with fetch, update, delete, executions and retry. The object you called fetch on does not change.

Example

Basic usage: read one webhook

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const webhook = await stack.webhook('<WEBHOOK_UID>').fetch()
  console.log(webhook.name, webhook.channels, webhook.destinations[0].target_url)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: pass query parameters with the request

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

// Query parameters to send with the request
const param = {}

try {
  const webhook = await stack.webhook('<WEBHOOK_UID>').fetch(param)
  console.log(webhook.uid)
} catch (error) {
  console.error(error.errorMessage)
}

fetchAll

fetchAll retrieves every webhook of the stack.

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}

Returns: Promise<ContentstackCollection>. The webhooks of the stack.

Validation

  • There is no client-side validation.
  • fetchAll exists only on stack.webhook(). On stack.webhook('<WEBHOOK_UID>') it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends GET /v3/webhooks with every key of param as a query parameter, as Get all webhooks describes.
  • Resolves to a ContentstackCollection. Its items array holds one Webhook object per webhook, each with fetch, update, delete, executions and retry.
  • Use fetchAll to find the UID of a webhook for stack.webhook('<WEBHOOK_UID>').

Example

Basic usage: list the webhooks of a stack

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const webhooks = await stack.webhook().fetchAll()
  for (const webhook of webhooks.items) {
    console.log(webhook.uid, webhook.name, webhook.disabled)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: pass query parameters with the request

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

// Query parameters to send with the request
const param = {}

try {
  const webhooks = await stack.webhook().fetchAll(param)
  console.log(webhooks.items.length)
} catch (error) {
  console.error(error.errorMessage)
}

import

import uploads a JSON file of webhook settings. On stack.webhook() it creates a new webhook, and on stack.webhook('<WEBHOOK_UID>') it updates that webhook.

NameTypeDescription
data (required)object

Import options.

Default: Not applicable
data.webhook (required)string

Path to the webhook JSON file on disk.

Default: Not applicable

Returns: Promise<Webhook>. The imported webhook.

Validation

  • There is no client-side validation. import does not check that the file exists or holds valid JSON.
  • A missing data.webhook rejects the returned promise with an Error whose code is ERR_INVALID_ARG_TYPE, before any request, because Node.js cannot open a file without a path.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • On stack.webhook(), sends POST /v3/webhooks/import, as Import a Webhook describes.
  • On stack.webhook('<WEBHOOK_UID>'), sends POST /v3/webhooks/{webhook_uid}/import, which updates the details of that webhook, as Import an Existing Webhook describes.
  • Sends the file as multipart/form-data in a form field named webhook. The SDK reads the file with the Node.js fs module, so import runs in Node.js only.
  • The file holds the webhook under a webhook key, in the same shape as the body of create.
  • Resolves to a Webhook object that the SDK builds from the webhook key of the response.

Example

Basic usage: import a new webhook from a file

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const webhook = await stack.webhook().import({ webhook: '<FILE_PATH>' })
  console.log(webhook.uid, webhook.name)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

Edge case: update an existing webhook from a file

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  // On an object with a UID, import updates that webhook instead of creating one
  const webhook = await stack.webhook('<WEBHOOK_UID>').import({ webhook: '<FILE_PATH>' })
  console.log(webhook.uid, webhook.channels)
} catch (error) {
  console.error(error.errorMessage)
}

removeHeader

removeHeader removes one header from the requests that this webhook object sends.

NameTypeDescription
key (required)string

Name of the header to remove.

Default: Not applicable

Returns: Webhook. The same webhook object, for chaining.

Validation

  • There is no client-side validation. A null or undefined key, or a key that the object does not hold, leaves the headers unchanged, and removeHeader returns the same object.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. removeHeader sends no request.
  • The first header change on this object copies the headers that it inherited from the stack. The change then applies to this object only, not to the stack or to other objects that the same stack creates.
  • Every request method of this object sends its headers. The objects that those methods return carry the same headers.
  • removeHeader can remove a header that the object inherited from the stack, such as branch. The stack and its other objects keep that header.
  • Do not remove api_key. Without it, the API cannot tell which stack the request is for.

Example

Basic usage: drop a header that you added earlier

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const webhook = stack.webhook('<WEBHOOK_UID>')
  .addHeaderDict({ 'x-request-id': 'docs-123', 'x-trace-id': 'trace-456' })
  .removeHeader('x-trace-id')
console.log('x-trace-id' in webhook.stackHeaders) // false

retry

retry asks the API to run one execution of the webhook again, after the webhook has finished its automatic attempts. The following table lists its parameters.

NameTypeDescription
executionUid (required)string

UID of the execution to run again.

Default: Not applicable

Returns: Promise<object>. The API response for the retry.

Validation

  • There is no client-side validation. A missing executionUid sends a body without execution_uid, and the API rejects it.
  • retry exists only on stack.webhook('<WEBHOOK_UID>') and on the Webhook objects that fetch, create, fetchAll and import return. On stack.webhook() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends POST /v3/webhooks/{webhook_uid}/retry with the body { execution_uid: executionUid }. The path holds the webhook UID of the object, and the body holds the execution UID.
  • The Retry a webhook request in the API reference puts the execution UID in the path instead.
  • Read the execution UID from the uid of an execution that executions returns.
  • Resolves to the response body as a plain object.
  • This request is separate from the automatic retry that the SDK applies to 429 responses.

Example

Basic usage: retry the newest failed execution

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })
const webhook = stack.webhook('<WEBHOOK_UID>')

try {
  const response = await webhook.executions({ query: { status: { $gte: '400', $lte: '599' } } })
  if (response.webhooks.length > 0) {
    const result = await webhook.retry(response.webhooks[0].uid)
    console.log(result)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: retry an execution by its UID

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const result = await stack.webhook('<WEBHOOK_UID>').retry('<EXECUTION_UID>')
  console.log(result)
} catch (error) {
  console.error(error.errorMessage)
}

update

update saves the current properties of the webhook object to the webhook.

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}

Returns: Promise<Webhook>. The updated webhook.

Validation

  • There is no client-side validation.
  • update exists only on stack.webhook('<WEBHOOK_UID>') and on the Webhook objects that fetch, create, fetchAll and import return. On stack.webhook() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends PUT /v3/webhooks/{webhook_uid} with every key of param as a query parameter, as Update webhook describes.
  • The body is { webhook: { ... } } with every data property of the object. The SDK leaves out uid, urlPath, stackHeaders, api_key, org_uid and the created_*, updated_* and deleted_at fields.
  • update sends what the object holds, not only what you changed. Call fetch first, then change the properties and call update.
  • Set disabled to true to turn the webhook off, or to false to turn it on.
  • Resolves to a new Webhook object that the SDK builds from the response.

Example

Basic usage: add a channel to a webhook

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const webhook = await stack.webhook('<WEBHOOK_UID>').fetch()
  webhook.channels.push('content_types.entries.publish')
  const updated = await webhook.update()
  console.log(updated.channels)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: turn a webhook off and pass query parameters

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const webhook = await stack.webhook('<WEBHOOK_UID>').fetch()
  webhook.disabled = true
  // Query parameters to send with the request
  const param = {}
  const updated = await webhook.update(param)
  console.log(updated.disabled)
} catch (error) {
  console.error(error.errorMessage)
}