//native
type Telnyx = {
apiKey: string
}
/**
* Get the list of phone numbers assigned to a channel zone
* Retrieve the assigned phone numbers in a channel zone. Phone numbers assigned to a channel zone can receive concurrent calls up to the quantity reserved in that channel zone. Additional concurrent calls are rejected with a busy signal.
*/
export async function main(
auth: Telnyx,
channel_zone_id: string,
page_number_: string | undefined,
page_size_: string | undefined
) {
const url = new URL(
`https://api.telnyx.com/v2/channel_zones/${channel_zone_id}/channel_zone_phone_numbers`
)
for (const [k, v] of [
['page[number]', page_number_],
['page[size]', page_size_]
]) {
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