Webhooks
Manage webhooks in the project environment.
The Webhooks API class provides methods to interact with webhooks in the selected project environments.
Method parameters
When using this API you need to pass the project name or ID and environment name or ID to the webhooks method.
// pass the project and environment to the webhooks method
await stashbase.webhooks({ project: 'my-project', environment: 'api-dev' }).list()List
Retrieves a list of webhooks in the selected 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({ project: 'my-project', environment: 'api-dev' })
.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({ project: 'my-project', environment: 'api-dev' })
.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 signle 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({ project: 'project', environment: 'api-dev' })
.listLogs('whk_4i1gbnewYBnCTZg3Sbye2c', {
page: 2,
pageSize: 20,
})
if (error) {
// handle error
} else {
const { data: logs, pagination } = data
}Create
Creates a new webhook in the selected environment. The method returns the created webhook object with properties id and signingSecret.
Parameters
This method takes and object CreateWebhookData parameter with the following properties:
Prop
Type
Example
const webhook = {}
const { data, error } = await stashbase
.webhooks({ project: 'my-project', environment: 'api-dev' })
.create({
url: 'https://example.com/webhook',
enabled: true,
})
if (error) {
// handle error
} else {
// ok
const { id } = data
}Enable
Enables a webhook by its id.
Parameters
This method takes a single parameter.
Prop
Type
Example
const { error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.enable('whk_4i1gbnewYBnCTZg3Sbye2c')
if (error) {
// handle error
}Disable
Disable a webhook by its id.
Parameters
This method takes a single parameter.
Prop
Type
Example
const { error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.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({ project: 'project', environment: 'api-dev' })
.update('whk_4i1gbnewYBnCTZg3Sbye2c', {
description: 'This is a new description for the webhook',
})
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
This method takes a single parameter.
Prop
Type
Example
const { data, error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.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 { data, error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.test('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 { data, error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.getSigningSecret('whk_4i1gbnewYBnCTZg3Sbye2c')
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 a single parameter.
Prop
Type
Example
const { data, error } = await stashbase
.webhooks({ project: 'project', environment: 'api-dev' })
.getSigningSecret('whk_4i1gbnewYBnCTZg3Sbye2c')
if (error) {
// handle error
} else {
const { signingSecret } = data
console.log(signingSecret)
}