Edits history of script submission #20280 for ' Retrieve an organizations events count by project (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve an organizations events count by project
     * Query summarized event counts by project for your Organization. Also see https://docs.sentry.io/api/organizations/retrieve-event-counts-for-an-organization-v2/ for reference.
     */
    export async function main(
    	auth: RT.Sentry,
    	field: 'sum(quantity)' | 'sum(times_seen)' | undefined,
    	statsPeriod?: string | undefined,
    	interval?: string | undefined,
    	start?: string | undefined,
    	end?: string | undefined,
    	project?: string | undefined,
    	category?: 'error' | 'transaction' | 'attachment' | 'replays' | 'profiles' | undefined,
    	outcome?:
    		| 'accepted'
    		| 'filtered'
    		| 'rate_limited'
    		| 'invalid'
    		| 'abuse'
    		| 'client_discard'
    		| 'cardinality_limited'
    		| undefined,
    	reason?: string | undefined,
    	download?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/stats-summary/`
    	)
    	for (const [k, v] of [
    		['field', field],
    		['statsPeriod', statsPeriod],
    		['interval', interval],
    		['start', start],
    		['end', end],
    		['project', project],
    		['category', category],
    		['outcome', outcome],
    		['reason', reason],
    		['download', download]
    	]) {
    		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