Edits history of script submission #20290 for ' Retrieve release health session statistics (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve release health session statistics
     * Returns a time series of release health session statistics for projects bound to an organization.
     */
    export async function main(
    	auth: RT.Sentry,
    	field: string | undefined,
    	start?: string | undefined,
    	end?: string | undefined,
    	environment?: string | undefined,
    	statsPeriod?: string | undefined,
    	project?: string | undefined,
    	per_page?: string | undefined,
    	interval?: string | undefined,
    	groupBy?: string | undefined,
    	orderBy?: string | undefined,
    	includeTotals?: string | undefined,
    	includeSeries?: string | undefined,
    	query?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/sessions/`
    	)
    	for (const [k, v] of [
    		['field', field],
    		['start', start],
    		['end', end],
    		['environment', environment],
    		['statsPeriod', statsPeriod],
    		['project', project],
    		['per_page', per_page],
    		['interval', interval],
    		['groupBy', groupBy],
    		['orderBy', orderBy],
    		['includeTotals', includeTotals],
    		['includeSeries', includeSeries],
    		['query', query]
    	]) {
    		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