0

Retrieve account usage totals

by
Published Oct 17, 2025

Get aggregated usage information for an account's data during a time period.

Script mezmo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve account usage totals
4
 * Get aggregated usage information for an account's data during a time period.
5
 */
6
export async function main(auth: RT.Mezmo, from: string | undefined, to: string | undefined) {
7
	const url = new URL(`https://api.mezmo.com/v2/usage`)
8
	for (const [k, v] of [
9
		['from', from],
10
		['to', to]
11
	]) {
12
		if (v !== undefined && v !== '') {
13
			url.searchParams.append(k, v)
14
		}
15
	}
16
	const response = await fetch(url, {
17
		method: 'GET',
18
		headers: {
19
			Authorization: 'Token ' + auth.apiKey
20
		},
21
		body: undefined
22
	})
23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27
	return await response.json()
28
}
29