0

Create an issue alert rule for a project

by
Published Oct 17, 2025

Create a new issue alert rule for the given project.

Script sentry Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create an issue alert rule for a project
4
 * Create a new issue alert rule for the given project.
5
 */
6
export async function main(auth: RT.Sentry, project_id_or_slug: string, body: Body) {
7
	const url = new URL(
8
		`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/rules/`
9
	)
10

11
	const response = await fetch(url, {
12
		method: 'POST',
13
		headers: {
14
			'Content-Type': 'application/json',
15
			Authorization: 'Bearer ' + auth.token
16
		},
17
		body: JSON.stringify(body)
18
	})
19
	if (!response.ok) {
20
		const text = await response.text()
21
		throw new Error(`${response.status} ${text}`)
22
	}
23
	return await response.json()
24
}
25

26
/* eslint-disable */
27
/**
28
 * This file was automatically generated by json-schema-to-typescript.
29
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
30
 * and run json-schema-to-typescript to regenerate this file.
31
 */
32

33
export interface Body {
34
	/**
35
	 * The name for the rule.
36
	 */
37
	name: string
38
	/**
39
	 * How often to perform the actions once for an issue, in minutes. The valid range is `5` to `43200`.
40
	 */
41
	frequency: number
42
	/**
43
	 * A string determining which of the conditions need to be true before any filters are evaluated.
44
	 *
45
	 * * `all` - All conditions must evaluate to true.
46
	 * * `any` - At least one of the conditions must evaluate to true.
47
	 * * `none` - All conditions must evaluate to false.
48
	 */
49
	actionMatch: 'all' | 'any' | 'none'
50
	/**
51
	 *
52
	 * A list of triggers that determine when the rule fires. See below for a list of possible conditions.
53
	 *
54
	 * **A new issue is created**
55
	 * ```json
56
	 * {
57
	 *     "id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"
58
	 * }
59
	 * ```
60
	 *
61
	 * **The issue changes state from resolved to unresolved**
62
	 * ```json
63
	 * {
64
	 *     "id": "sentry.rules.conditions.regression_event.RegressionEventCondition"
65
	 * }
66
	 * ```
67
	 *
68
	 * **The issue is seen more than `value` times in `interval`**
69
	 * - `value` - An integer
70
	 * - `interval` - Valid values are `1m`, `5m`, `15m`, `1h`, `1d`, `1w` and `30d` (`m` for minutes, `h` for hours, `d` for days, and `w` for weeks).
71
	 * ```json
72
	 * {
73
	 *     "id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
74
	 *     "value": 500,
75
	 *     "interval": "1h"
76
	 * }
77
	 * ```
78
	 *
79
	 * **The issue is seen by more than `value` users in `interval`**
80
	 * - `value` - An integer
81
	 * - `interval` - Valid values are `1m`, `5m`, `15m`, `1h`, `1d`, `1w` and `30d` (`m` for minutes, `h` for hours, `d` for days, and `w` for weeks).
82
	 * ```json
83
	 * {
84
	 *     "id": "sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition",
85
	 *     "value": 1000,
86
	 *     "interval": "15m"
87
	 * }
88
	 * ```
89
	 *
90
	 * **The issue affects more than `value` percent of sessions in `interval`**
91
	 * - `value` - A float
92
	 * - `interval` - Valid values are `5m`, `10m`, `30m`, and `1h` (`m` for minutes, `h` for hours).
93
	 * ```json
94
	 * {
95
	 *     "id": "sentry.rules.conditions.event_frequency.EventFrequencyPercentCondition",
96
	 *     "value": 50.0,
97
	 *     "interval": "10m"
98
	 * }
99
	 * ```
100
	 *
101
	 */
102
	conditions: {
103
		[k: string]: unknown
104
	}[]
105
	/**
106
	 *
107
	 * A list of actions that take place when all required conditions and filters for the rule are met. See below for a list of possible actions.
108
	 *
109
	 * **Send a notification to Suggested Assignees**
110
	 * - `fallthroughType` - Who the notification should be sent to if there are no suggested assignees. Valid values are `ActiveMembers`, `AllMembers`, and `NoOne`.
111
	 * ```json
112
	 * {
113
	 *     "id" - "sentry.mail.actions.NotifyEmailAction",
114
	 *     "targetType" - "IssueOwners",
115
	 *     "fallthroughType" - "ActiveMembers"
116
	 * }
117
	 * ```
118
	 *
119
	 * **Send a notification to a Member or a Team**
120
	 * - `targetType` - One of `Member` or `Team`.
121
	 * - `fallthroughType` - Who the notification should be sent to if it cannot be sent to the original target. Valid values are `ActiveMembers`, `AllMembers`, and `NoOne`.
122
	 * - `targetIdentifier` - The ID of the Member or Team the notification should be sent to.
123
	 * ```json
124
	 * {
125
	 *     "id": "sentry.mail.actions.NotifyEmailAction",
126
	 *     "targetType": "Team"
127
	 *     "fallthroughType": "AllMembers"
128
	 *     "targetIdentifier": 4524986223
129
	 * }
130
	 * ```
131
	 *
132
	 * **Send a Slack notification**
133
	 * - `workspace` - The integration ID associated with the Slack workspace.
134
	 * - `channel` - The name of the channel to send the notification to (e.g., #critical, Jane Schmidt).
135
	 * - `channel_id` (optional) - The ID of the channel to send the notification to.
136
	 * - `tags` (optional) - A string of tags to show in the notification, separated by commas (e.g., "environment, user, my_tag").
137
	 * - `notes` (optional) - Text to show alongside the notification. To @ a user, include their user id like `@<USER_ID>`. To include a clickable link, format the link and title like `<http://example.com|Click Here>`.
138
	 * ```json
139
	 * {
140
	 *     "id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
141
	 *     "workspace": 293854098,
142
	 *     "channel": "#warning",
143
	 *     "tags": "environment,level"
144
	 *     "notes": "Please <http://example.com|click here> for triage information"
145
	 * }
146
	 * ```
147
	 *
148
	 * **Send a Microsoft Teams notification**
149
	 * - `team` - The integration ID associated with the Microsoft Teams team.
150
	 * - `channel` - The name of the channel to send the notification to.
151
	 * ```json
152
	 * {
153
	 *     "id": "sentry.integrations.msteams.notify_action.MsTeamsNotifyServiceAction",
154
	 *     "team": 23465424,
155
	 *     "channel": "General"
156
	 * }
157
	 * ```
158
	 *
159
	 * **Send a Discord notification**
160
	 * - `server` - The integration ID associated with the Discord server.
161
	 * - `channel_id` - The ID of the channel to send the notification to.
162
	 * - `tags` (optional) - A string of tags to show in the notification, separated by commas (e.g., "environment, user, my_tag").
163
	 * ```json
164
	 * {
165
	 *     "id": "sentry.integrations.discord.notify_action.DiscordNotifyServiceAction",
166
	 *     "server": 63408298,
167
	 *     "channel_id": 94732897,
168
	 *     "tags": "browser,user"
169
	 * }
170
	 * ```
171
	 *
172
	 * **Create a Jira Ticket**
173
	 * - `integration` - The integration ID associated with Jira.
174
	 * - `project` - The ID of the Jira project.
175
	 * - `issuetype` - The ID of the type of issue that the ticket should be created as.
176
	 * - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the ticket as objects.
177
	 * ```json
178
	 * {
179
	 *     "id": "sentry.integrations.jira.notify_action.JiraCreateTicketAction",
180
	 *     "integration": 321424,
181
	 *     "project": "349719"
182
	 *     "issueType": "1"
183
	 * }
184
	 * ```
185
	 *
186
	 * **Create a Jira Server Ticket**
187
	 * - `integration` - The integration ID associated with Jira Server.
188
	 * - `project` - The ID of the Jira Server project.
189
	 * - `issuetype` - The ID of the type of issue that the ticket should be created as.
190
	 * - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the ticket as objects.
191
	 * ```json
192
	 * {
193
	 *     "id": "sentry.integrations.jira_server.notify_action.JiraServerCreateTicketAction",
194
	 *     "integration": 321424,
195
	 *     "project": "349719"
196
	 *     "issueType": "1"
197
	 * }
198
	 * ```
199
	 *
200
	 * **Create a GitHub Issue**
201
	 * - `integration` - The integration ID associated with GitHub.
202
	 * - `repo` - The name of the repository to create the issue in.
203
	 * - `title` - The title of the issue.
204
	 * - `body` (optional) - The contents of the issue.
205
	 * - `assignee` (optional) - The GitHub user to assign the issue to.
206
	 * - `labels` (optional) - A list of labels to assign to the issue.
207
	 * ```json
208
	 * {
209
	 *     "id": "sentry.integrations.github.notify_action.GitHubCreateTicketAction",
210
	 *     "integration": 93749,
211
	 *     "repo": default,
212
	 *     "title": "My Test Issue",
213
	 *     "assignee": "Baxter the Hacker",
214
	 *     "labels": ["bug", "p1"]
215
	 *     ""
216
	 * }
217
	 * ```
218
	 *
219
	 * **Create a GitHub Enterprise Issue**
220
	 * - `integration` - The integration ID associated with GitHub Enterprise.
221
	 * - `repo` - The name of the repository to create the issue in.
222
	 * - `title` - The title of the issue.
223
	 * - `body` (optional) - The contents of the issue.
224
	 * - `assignee` (optional) - The GitHub user to assign the issue to.
225
	 * - `labels` (optional) - A list of labels to assign to the issue.
226
	 * ```json
227
	 * {
228
	 *     "id": "sentry.integrations.github_enterprise.notify_action.GitHubEnterpriseCreateTicketAction",
229
	 *     "integration": 93749,
230
	 *     "repo": default,
231
	 *     "title": "My Test Issue",
232
	 *     "assignee": "Baxter the Hacker",
233
	 *     "labels": ["bug", "p1"]
234
	 *     ""
235
	 * }
236
	 * ```
237
	 *
238
	 * **Create an Azure DevOps work item**
239
	 * - `integration` - The integration ID.
240
	 * - `project` - The ID of the Azure DevOps project.
241
	 * - `work_item_type` - The type of work item to create.
242
	 * - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the work item as objects.
243
	 * ```json
244
	 * {
245
	 *     "id": "sentry.integrations.vsts.notify_action.AzureDevopsCreateTicketAction",
246
	 *     "integration": 294838,
247
	 *     "project": "0389485",
248
	 *     "work_item_type": "Microsoft.VSTS.WorkItemTypes.Task",
249
	 * }
250
	 * ```
251
	 *
252
	 * **Send a PagerDuty notification**
253
	 * - `account` - The integration ID associated with the PagerDuty account.
254
	 * - `service` - The ID of the service to send the notification to.
255
	 * - `severity` - The severity of the Pagerduty alert. This is optional, the default is `critical` for fatal issues, `error` for error issues, `warning` for warning issues, and `info` for info and debug issues.
256
	 * ```json
257
	 * {
258
	 *     "id": "sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction",
259
	 *     "account": 92385907,
260
	 *     "service": 9823924,
261
	 *     "severity": "critical"
262
	 * }
263
	 * ```
264
	 *
265
	 * **Send an Opsgenie notification**
266
	 * - `account` - The integration ID associated with the Opsgenie account.
267
	 * - `team` - The ID of the Opsgenie team to send the notification to.
268
	 * - `priority` - The priority of the Opsgenie alert. This is optional, the default is `P3`.
269
	 * ```json
270
	 * {
271
	 *     "id": "sentry.integrations.opsgenie.notify_action.OpsgenieNotifyTeamAction",
272
	 *     "account": 8723897589,
273
	 *     "team": "9438930258-fairy",
274
	 *     "priority": "P1"
275
	 * }
276
	 * ```
277
	 *
278
	 * **Send a notification to a service**
279
	 * - `service` - The plugin slug.
280
	 * ```json
281
	 * {
282
	 *     "id": "sentry.rules.actions.notify_event_service.NotifyEventServiceAction",
283
	 *     "service": "mail"
284
	 * }
285
	 * ```
286
	 *
287
	 * **Send a notification to a Sentry app with a custom webhook payload**
288
	 * - `settings` - A list of objects denoting the settings each action will be created with. All required fields must be included.
289
	 * - `sentryAppInstallationUuid` - The ID for the Sentry app
290
	 * ```json
291
	 * {
292
	 *     "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction",
293
	 *     "settings": [
294
	 *         {"name": "title", "value": "Team Rocket"},
295
	 *         {"name": "summary", "value": "We're blasting off again."},
296
	 *     ],
297
	 *     "sentryAppInstallationUuid": 643522
298
	 *     "hasSchemaFormConfig": true
299
	 * }
300
	 * ```
301
	 *
302
	 * **Send a notification (for all legacy integrations)**
303
	 * ```json
304
	 * {
305
	 *     "id": "sentry.rules.actions.notify_event.NotifyEventAction"
306
	 * }
307
	 * ```
308
	 *
309
	 */
310
	actions: {
311
		[k: string]: unknown
312
	}[]
313
	/**
314
	 * The name of the environment to filter by.
315
	 */
316
	environment?: string
317
	/**
318
	 * The ID of the team or user that owns the rule.
319
	 */
320
	owner?: string
321
	/**
322
	 * A string determining which filters need to be true before any actions take place. Required when a value is provided for `filters`.
323
	 *
324
	 * * `all` - All filters must evaluate to true.
325
	 * * `any` - At least one of the filters must evaluate to true.
326
	 * * `none` - All filters must evaluate to false.
327
	 */
328
	filterMatch?: 'all' | 'any' | 'none'
329
	/**
330
	 *
331
	 * A list of filters that determine if a rule fires after the necessary conditions have been met. See below for a list of possible filters.
332
	 *
333
	 * **The issue is `comparison_type` than `value` `time`**
334
	 * - `comparison_type` - One of `older` or `newer`
335
	 * - `value` - An integer
336
	 * - `time` - The unit of time. Valid values are `minute`, `hour`, `day`, and `week`.
337
	 * ```json
338
	 * {
339
	 *     "id": "sentry.rules.filters.age_comparison.AgeComparisonFilter",
340
	 *     "comparison_type": "older",
341
	 *     "value": 3,
342
	 *     "time": "week"
343
	 * }
344
	 * ```
345
	 *
346
	 * **The issue has happened at least `value` times**
347
	 * - `value` - An integer
348
	 * ```json
349
	 * {
350
	 *     "id": "sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter",
351
	 *     "value": 120
352
	 * }
353
	 * ```
354
	 *
355
	 * **The issue is assigned to No One**
356
	 * ```json
357
	 * {
358
	 *     "id": "sentry.rules.filters.assigned_to.AssignedToFilter",
359
	 *     "targetType": "Unassigned"
360
	 * }
361
	 * ```
362
	 *
363
	 * **The issue is assigned to `targetType`**
364
	 * - `targetType` - One of `Team` or `Member`
365
	 * - `targetIdentifier` - The target's ID
366
	 * ```json
367
	 * {
368
	 *     "id": "sentry.rules.filters.assigned_to.AssignedToFilter",
369
	 *     "targetType": "Member",
370
	 *     "targetIdentifier": 895329789
371
	 * }
372
	 * ```
373
	 *
374
	 * **The event is from the latest release**
375
	 * ```json
376
	 * {
377
	 *     "id": "sentry.rules.filters.latest_release.LatestReleaseFilter"
378
	 * }
379
	 * ```
380
	 *
381
	 * **The issue's category is equal to `value`**
382
	 * - `value` - An integer correlated with a category. Valid values are `1` (Error), `2` (Performance), `3` (Profile), `4` (Cron), and `5` (Replay).
383
	 * ```json
384
	 * {
385
	 *     "id": "sentry.rules.filters.issue_category.IssueCategoryFilter",
386
	 *     "value": 2
387
	 * }
388
	 * ```
389
	 *
390
	 * **The event's `attribute` value `match` `value`**
391
	 * - `attribute` - Valid values are `message`, `platform`, `environment`, `type`, `error.handled`, `error.unhandled`, `error.main_thread`, `exception.type`, `exception.value`, `user.id`, `user.email`, `user.username`, `user.ip_address`, `http.method`, `http.url`, `http.status_code`, `sdk.name`, `stacktrace.code`, `stacktrace.module`, `stacktrace.filename`, `stacktrace.abs_path`, `stacktrace.package`, `unreal.crash_type`, `app.in_foreground`.
392
	 * - `match` - The comparison operator. Valid values are `eq` (equals), `ne` (does not equal), `sw` (starts with), `ew` (ends with), `co` (contains), `nc` (does not contain), `is` (is set), and `ns` (is not set).
393
	 * - `value` - A string. Not required when `match` is `is` or `ns`.
394
	 * ```json
395
	 * {
396
	 *     "id": "sentry.rules.conditions.event_attribute.EventAttributeCondition",
397
	 *     "attribute": "http.url",
398
	 *     "match": "nc",
399
	 *     "value": "localhost"
400
	 * }
401
	 * ```
402
	 *
403
	 * **The event's tags match `key` `match` `value`**
404
	 * - `key` - The tag
405
	 * - `match` - The comparison operator. Valid values are `eq` (equals), `ne` (does not equal), `sw` (starts with), `ew` (ends with), `co` (contains), `nc` (does not contain), `is` (is set), and `ns` (is not set).
406
	 * - `value` - A string. Not required when `match` is `is` or `ns`.
407
	 * ```json
408
	 * {
409
	 *     "id": "sentry.rules.filters.tagged_event.TaggedEventFilter",
410
	 *     "key": "level",
411
	 *     "match": "eq"
412
	 *     "value": "error"
413
	 * }
414
	 * ```
415
	 *
416
	 * **The event's level is `match` `level`**
417
	 * - `match` - Valid values are `eq`, `gte`, and `lte`.
418
	 * - `level` - Valid values are `50` (fatal), `40` (error), `30` (warning), `20` (info), `10` (debug), `0` (sample).
419
	 * ```json
420
	 * {
421
	 *     "id": "sentry.rules.filters.level.LevelFilter",
422
	 *     "match": "gte"
423
	 *     "level": "50"
424
	 * }
425
	 * ```
426
	 *
427
	 */
428
	filters?: {
429
		[k: string]: unknown
430
	}[]
431
	[k: string]: unknown
432
}
433