//native
type Telnyx = {
apiKey: string
}
/**
* Get usage report sync
* Generate and fetch messaging usage report synchronously. This endpoint will both generate and fetch the messaging report over a specified time period. No polling is necessary but the response may take up to a couple of minutes.
*/
export async function main(
auth: Telnyx,
start_date: string | undefined,
end_date: string | undefined,
aggregation_type: 'NO_AGGREGATION' | 'PROFILE' | 'TAGS' | undefined,
profiles: string | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/reports/mdr_usage_reports/sync`)
for (const [k, v] of [
['start_date', start_date],
['end_date', end_date],
['aggregation_type', aggregation_type],
['profiles', profiles]
]) {
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