@anthropic-ai/sdk
Version:
The official TypeScript library for the Anthropic API
218 lines • 9.62 kB
JavaScript
import { APIResource } from "../../../core/resource.mjs";
import { Page } from "../../../core/pagination.mjs";
import { buildHeaders } from "../../../internal/headers.mjs";
import { startApiCallSpan } from "../../../internal/tracing.mjs";
import { path } from "../../../internal/utils/path.mjs";
export class Webhooks extends APIResource {
/**
* Create an organization webhook endpoint.
*
* An organization webhook endpoint belongs to the organization rather than to one
* of its workspaces. An organization can have at most 32 organization webhook
* endpoints, enabled or disabled.
*
* The response includes the endpoint's signing secret. No read returns it, so
* store it when you receive it.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* const betaNewOrganizationWebhookEndpoint =
* await client.beta.organization.webhooks.create({
* enabled_events: [
* 'user_profile.enforcement_action_opened',
* ],
* url: 'x',
* });
* ```
*/
create(params, options) {
const { betas, ...body } = params;
return this._client.post('/v1/organizations/webhooks?beta=true', {
body,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.create', options, {
route: '/v1/organizations/webhooks',
createdIDAttribute: 'anthropic.organization.webhook.id',
}),
});
}
/**
* Retrieve an organization webhook endpoint by ID.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* const betaOrganizationWebhookEndpoint =
* await client.beta.organization.webhooks.retrieve(
* 'webhook_endpoint_id',
* );
* ```
*/
retrieve(webhookEndpointID, params = {}, options) {
const { betas } = params ?? {};
return this._client.get(path `/v1/organizations/webhooks/${webhookEndpointID}?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.retrieve', options, {
route: '/v1/organizations/webhooks/{webhook_endpoint_id}',
attributes: { 'anthropic.organization.webhook.id': webhookEndpointID },
}),
});
}
/**
* Update an organization webhook endpoint. Only the fields you send are changed.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* const betaOrganizationWebhookEndpoint =
* await client.beta.organization.webhooks.update(
* 'webhook_endpoint_id',
* );
* ```
*/
update(webhookEndpointID, params, options) {
const { betas, ...body } = params;
return this._client.post(path `/v1/organizations/webhooks/${webhookEndpointID}?beta=true`, {
body,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.update', options, {
route: '/v1/organizations/webhooks/{webhook_endpoint_id}',
attributes: { 'anthropic.organization.webhook.id': webhookEndpointID },
}),
});
}
/**
* List the organization's webhook endpoints.
*
* An organization webhook endpoint belongs to the organization rather than to one
* of its workspaces. The list does not include webhook endpoints that belong to a
* workspace.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const betaOrganizationWebhookEndpoint of client.beta.organization.webhooks.list()) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { betas, ...query } = params ?? {};
return this._client.getAPIList('/v1/organizations/webhooks?beta=true', (Page), {
query,
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.list', options, {
route: '/v1/organizations/webhooks',
queryParams: ['after_id', 'before_id', 'limit', 'order'],
}),
});
}
/**
* Delete an organization webhook endpoint.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* const betaDeletedOrganizationWebhookEndpoint =
* await client.beta.organization.webhooks.delete(
* 'webhook_endpoint_id',
* );
* ```
*/
delete(webhookEndpointID, params = {}, options) {
const { betas } = params ?? {};
return this._client.delete(path `/v1/organizations/webhooks/${webhookEndpointID}?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.delete', options, {
route: '/v1/organizations/webhooks/{webhook_endpoint_id}',
attributes: { 'anthropic.organization.webhook.id': webhookEndpointID },
}),
});
}
/**
* Replace an organization webhook endpoint's signing secret. The old secret stops
* working immediately. The new secret is returned only in this response.
*
* Every request must include the beta header
* `anthropic-beta: webhooks-2026-10-07`. A request without it returns `404`,
* exactly as if this API did not exist. Anthropic turns organization webhook
* endpoints on for each organization; until yours is on, requests also return
* `404`. Organization webhook endpoints are in beta and are not available to
* organizations with HIPAA readiness enabled.
*
* @example
* ```ts
* const betaOrganizationWebhookEndpointSigningSecret =
* await client.beta.organization.webhooks.regenerateSigningSecret(
* 'webhook_endpoint_id',
* );
* ```
*/
regenerateSigningSecret(webhookEndpointID, params = {}, options) {
const { betas } = params ?? {};
return this._client.post(path `/v1/organizations/webhooks/${webhookEndpointID}/regenerate_signing_secret?beta=true`, {
...options,
headers: buildHeaders([
{ 'anthropic-beta': [...(betas ?? []), 'webhooks-2026-10-07'].toString() },
options?.headers,
]),
__span: startApiCallSpan(this._client, 'anthropic.organization.webhooks.regenerate_signing_secret', options, {
route: '/v1/organizations/webhooks/{webhook_endpoint_id}/regenerate_signing_secret',
attributes: { 'anthropic.organization.webhook.id': webhookEndpointID },
}),
});
}
}
//# sourceMappingURL=webhooks.mjs.map