//native
type Neondb = {
apiKey: string
}
/**
* Get account consumption metrics
* Retrieves consumption metrics for Scale and Business plan accounts. History begins at the time of upgrade.
Available for Scale and Business plan users only.
*/
export async function main(
auth: Neondb,
from: string | undefined,
to: string | undefined,
granularity: 'hourly' | 'daily' | 'monthly' | undefined,
org_id: string | undefined,
include_v1_metrics: string | undefined
) {
const url = new URL(`https://console.neon.tech/api/v2/consumption_history/account`)
for (const [k, v] of [
['from', from],
['to', to],
['granularity', granularity],
['org_id', org_id],
['include_v1_metrics', include_v1_metrics]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + 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 428 days ago