//native
type Telnyx = {
apiKey: string
}
/**
* List requirement groups
*
*/
export async function main(
auth: Telnyx,
filter_country_code_: string | undefined,
filter_phone_number_type_:
| 'local'
| 'toll_free'
| 'mobile'
| 'national'
| 'shared_cost'
| undefined,
filter_action_: 'ordering' | 'porting' | 'action' | undefined,
filter_status_: 'approved' | 'unapproved' | 'pending-approval' | 'declined' | undefined,
filter_customer_reference_: string | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/requirement_groups`)
for (const [k, v] of [
['filter[country_code]', filter_country_code_],
['filter[phone_number_type]', filter_phone_number_type_],
['filter[action]', filter_action_],
['filter[status]', filter_status_],
['filter[customer_reference]', filter_customer_reference_]
]) {
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