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/update-webhook.ts

28 lines · 955 B · TypeScript
import { assertWebhookId, boxRequest, failure, type Result } from './client.ts'
import type { Webhook, WebhookEventType } from './types.ts'

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

export type UpdateWebhookOutput = { webhook: Webhook }

/** Update a webhook's name, URL, or events without changing the signing secret. */
export default async function updateWebhook(
	input: UpdateWebhookInput,
): Promise<Result<UpdateWebhookOutput>> {
	const invalid = assertWebhookId(input?.webhookId)
	if (invalid) return failure<UpdateWebhookOutput>(invalid)
	const body: Record<string, unknown> = {}
	if (input.name !== undefined) body.name = input.name
	if (input.url !== undefined) body.url = input.url
	if (input.events !== undefined) body.events = input.events
	return boxRequest<UpdateWebhookOutput>({
		path: '/webhooks/' + input.webhookId,
		method: 'PATCH',
		body,
	})
}