Edits history of script submission #17231 for ' Export log lines (mezmo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Export log lines
     * Use this method to export logs in JSON format from a logging instance.
     */
    export async function main(
    	auth: RT.Mezmo,
    	from: string | undefined,
    	to: string | undefined,
    	size?: string | undefined,
    	hosts?: string | undefined,
    	apps?: string | undefined,
    	levels?: string | undefined,
    	query?: string | undefined,
    	prefer?: string | undefined,
    	pagination_id?: string | undefined
    ) {
    	const url = new URL(`https://api.mezmo.com/v2/export`)
    	for (const [k, v] of [
    		['from', from],
    		['to', to],
    		['size', size],
    		['hosts', hosts],
    		['apps', apps],
    		['levels', levels],
    		['query', query],
    		['prefer', prefer],
    		['pagination_id', pagination_id]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Token ' + auth.apiKey
    		},
    		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