Edits history of script submission #17268 for ' Retrieve account usage totals (mezmo)'

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