//native
/**
* Get device data usage
* Get a device's (IMSI) uplink and downlink data points, in bits per second, over a timespan in hours: 1, 4, 8, 24 or 72 (API default 72).
*/
export async function main(
auth: RT.EricssonEp5g,
imsi: string,
timespan: number | undefined
) {
const base = auth.base_url.replace(/\/+$/, "")
const url = new URL(
`${base}/v2/organization/${encodeURIComponent(auth.organization)}/site/${encodeURIComponent(auth.site)}/nc/imsi/${encodeURIComponent(imsi)}/datausage`
)
if (timespan != null) {
url.searchParams.append("timespan", String(timespan))
}
const response = await fetch(url, {
headers: {
"X-Api-Key": auth.api_key,
...(auth.user_role ? { "X-User-Role": auth.user_role } : {}),
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 hours ago