0

Update an outbound webhook

by
Published Dec 20, 2024

Updates an outbound webhook.

Script circleci Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Circleci = {
3
	token: string
4
}
5
/**
6
 * Update an outbound webhook
7
 * Updates an outbound webhook.
8
 */
9
export async function main(
10
	auth: Circleci,
11
	webhook_id: string,
12
	body: {
13
		name?: string
14
		events?: 'workflow-completed' | 'job-completed'[]
15
		url?: string
16
		'signing-secret'?: string
17
		'verify-tls'?: false | true
18
	}
19
) {
20
	const url = new URL(`https://circleci.com/api/v2/webhook/${webhook_id}`)
21

22
	const response = await fetch(url, {
23
		method: 'PUT',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			'Circle-Token': auth.token
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.json()
35
}
36