//native
type Telnyx = {
apiKey: string
}
/**
* Get paginated mdrs
* Fetch all Mdr records
*/
export async function main(
auth: Telnyx,
start_date: string | undefined,
end_date: string | undefined,
id: string | undefined,
direction: 'INBOUND' | 'OUTBOUND' | undefined,
profile: string | undefined,
cld: string | undefined,
cli: string | undefined,
status:
| 'GW_TIMEOUT'
| 'DELIVERED'
| 'DLR_UNCONFIRMED'
| 'DLR_TIMEOUT'
| 'RECEIVED'
| 'GW_REJECT'
| 'FAILED'
| undefined,
message_type: 'SMS' | 'MMS' | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/reports/mdrs`)
for (const [k, v] of [
['start_date', start_date],
['end_date', end_date],
['id', id],
['direction', direction],
['profile', profile],
['cld', cld],
['cli', cli],
['status', status],
['message_type', message_type]
]) {
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