0

Register a new service hook

by
Published Oct 17, 2025

Register a new service hook on a project. Events include: - event.alert: An alert is generated for an event (via rules). - event.created: A new event has been processed. This endpoint requires the 'servicehooks' feature to be enabled for your project.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Register a new service hook
4
 * Register a new service hook on a project.
5

6
Events include:
7

8
- event.alert: An alert is generated for an event (via rules).
9
- event.created: A new event has been processed.
10

11
This endpoint requires the 'servicehooks' feature to be enabled for your project.
12
 */
13
export async function main(auth: RT.Sentry, project_id_or_slug: string, body: Body) {
14
	const url = new URL(
15
		`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/hooks/`
16
	)
17

18
	const response = await fetch(url, {
19
		method: 'POST',
20
		headers: {
21
			'Content-Type': 'application/json',
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: JSON.stringify(body)
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32

33
/* eslint-disable */
34
/**
35
 * This file was automatically generated by json-schema-to-typescript.
36
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
37
 * and run json-schema-to-typescript to regenerate this file.
38
 */
39

40
export interface Body {
41
	/**
42
	 * The URL for the webhook.
43
	 */
44
	url: string
45
	/**
46
	 * The events to subscribe to.
47
	 */
48
	events: string[]
49
	[k: string]: unknown
50
}
51