Skip to content
← Public packages

@cameronpak/box

Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.

src/create-webhook.ts

26 lines · 868 B · TypeScript
import { boxRequest, type Result } from './client.ts'
import type { Webhook, WebhookEventType } from './types.ts'

export type CreateWebhookInput = {
	name?: string | null
	url: string
	events: Array<WebhookEventType>
}

export type CreateWebhookOutput = {
	webhook: Webhook
	/** Signing secret returned only on create or rotate. Store it; it is shown once. */
	secret: string
}

/**
 * Register an account-wide HTTPS endpoint for box.ready, box.error, and box.archived.
 * The signing secret is returned only in this response.
 */
export default async function createWebhook(
	input: CreateWebhookInput,
): Promise<Result<CreateWebhookOutput>> {
	const body: Record<string, unknown> = { url: input.url, events: input.events }
	if (input.name !== undefined) body.name = input.name
	return boxRequest<CreateWebhookOutput>({ path: '/webhooks', method: 'POST', body })
}