Edits history of script submission #20239 for ' List spike protection notifications (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * List spike protection notifications
     * Returns all Spike Protection Notification Actions for an organization.
    
    Notification Actions notify a set of members when an action has been triggered through a notification service such as Slack or Sentry.
    For example, organization owners and managers can receive an email when a spike occurs.
    
    You can use either the `project` or `projectSlug` query parameter to filter for certain projects. Note that if both are present, `projectSlug` takes priority.
     */
    export async function main(
    	auth: RT.Sentry,
    	project?: string | undefined,
    	project_id_or_slug?: string | undefined,
    	triggerType?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/notifications/actions/`
    	)
    	for (const [k, v] of [
    		['project', project],
    		['project_id_or_slug', project_id_or_slug],
    		['triggerType', triggerType]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago