Stashbase
Environment Client

Webhooks

Manage webhooks for your environment.

The Webhooks API class provides methods to interact with webhooks in the API key associated environment.

Ensure your API Key has the necessary permissions to manage webhooks.

List

Retrieves a list of webhooks associated with the current API key environment.

Parameters

This method takes one optional parameter.

Prop

Type

Options

An object with the following properties:

Prop

Type

Default sorting is created_at desc. When sorting by url or enabled, the API applies created_at desc as a secondary sort to keep results stable within ties.

Example

const { data, error } = await stashbase.webhooks.list({
  sortBy: 'url',
  order: 'asc',
})

if (error) {
  // handle error
} else {
  // do something with the data
}

Get

Retrieves a single webhook by its ID.

Parameters

This method takes two parameters.

Prop

Type

Example

const { data, error } = await stashbase.webhooks.get('whk_4i1gbnewYBnCTZg3Sbye2c')

if (error) {
  // handle error
} else {
  // do something with the data
}

List logs

Retrieves a list of logs for a specific webhook. Each log item represents a single webhook delivery attempt.

Parameters

This method takes two parameters.

Prop

Type

Options

An object with the following properties:

Prop

Type

Example

const { data, error } = await stashbase.webhooks.get('whk_4i1gbnewYBnCTZg3Sbye2c', {
  page: 2,
  pageSize: 20,
})

if (error) {
  // handle error
} else {
  // do something with the data
}

Get log

Retrieves a single log for a specific webhook. This returns webhook log with response body data if available.

Parameters

This method takes two parameters.

Prop

Type

Example

const { data, error } = await stashbase.webhooks.getLog('whk_4i1gbnewYBnCTZg3Sbye2c', 'whlog_cU3p8L746dz3fR3oD48bzs')

if (error) {
  // handle error
} else {
  // do something with the data
}

Create

Creates a new webhook in the API key associated environment. The method returns the created webhook object with id property.

Parameters

This method takes and object CreateWebhookData parameter with the following properties:

Prop

Type

Example

const { data, error } = await stashbase.webhooks.create({
  url: 'https://example.com/webhook',
  description: 'My awesome webhook',
  enabled: true,
})

if (error) {
  // handle error
} else {
  // do something with the data
}

Enable

Enables a webhook by its ID.

Parameters

This method takes a single parameter.

Prop

Type

Example

const { error } = await stashbase.webhooks.enable('whk_4i1gbnewYBnCTZg3Sbye2c')

if (error) {
  // handle error
}

Disable

Disables a webhook by its id.

Parameters

This method takes a single parameter.

Prop

Type

Example

const { error } = await stashbase.webhooks.disable('whk_4i1gbnewYBnCTZg3Sbye2c')

if (error) {
  // handle error
}

Update

Updates an existing webhook by its ID.

Parameters

This method takes two parameters.

Prop

Type

Data

The data object UpdateWebhookData can contain the following properties and at least one of them must be provided:

Prop

Type

Example

const { data, error } = await stashbase.webhooks.update('whk_4i1gbnewYBnCTZg3Sbye2c', {
  url: 'https://my-api.com/webhoo',
})

if (error) {
  // handle error
}

Test

Tests a webhook by sending a test payload. This method will send a payload with property live_mode set to false to the webhook target URL.

Parameters

Thos method takes a single parameter.

Prop

Type

Example

const { data, error } = await stashbase.webhooks.test('whk_4i1gbnewYBnCTZg3Sbye2c')

if (error) {
  // handle error
} else {
  // do something with the data
}

Delete

Delete single webhook by its id.

Parameters

This method takes a single parameter.

Prop

Type

Example

const { error } = await stashbase.webhooks.delete('whk_4i1gbnewYBnCTZg3Sbye2c')

if (error) {
  // handle error
}

Get signing secret

Retrieves the signing secret for a webhook.

Parameters

This method takes a single parameter.

Prop

Type

Example

const webhookId = 'wbk_4i1gbnewYBnCTZg3Sbye2c'
const { data, error } = await stashbase.webhooks.getSigningSecret(webhookId)

if (error) {
  // handle error
} else {
  const { signingSecret } = data
  console.log(signingSecret)
}

Rotate signing secret

Rotate the signing secret for a webhook. This method returns the new signing secret.

Rotating the signing secret will invalidate the previous secret. Make sure to update your webhook endpoint to use the new secret.

Parameters

This method takes one parameter:

Prop

Type

Example

const webhookId = 'whk_4i1gbnewYBnCTZg3Sbye2c'
const { data, error } = await stashbase.webhooks.rotateSigningSecret(webhookId)

if (error) {
  // handle error
} else {
  const { signingSecret } = data
  console.log(signingSecret)
}

On this page