Edits history of script submission #17255 for ' List Usage by Host (mezmo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * List Usage by Host
     * Lists aggregated usage information for all hosts during a time period.
     */
    export async function main(
    	auth: RT.Mezmo,
    	from: string | undefined,
    	to: string | undefined,
    	limit?: string | undefined,
    	retention?: string | undefined
    ) {
    	const url = new URL(`https://api.mezmo.com/v2/usage/hosts`)
    	for (const [k, v] of [
    		['from', from],
    		['to', to],
    		['limit', limit],
    		['retention', retention]
    	]) {
    		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