//native
type Telnyx = {
apiKey: string
}
/**
* List Ips
* Get all IPs belonging to the user that match the given filters.
*/
export async function main(
auth: Telnyx,
page_number_: string | undefined,
page_size_: string | undefined,
filter_connection_id_: string | undefined,
filter_ip_address_: string | undefined,
filter_port_: string | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/ips`)
for (const [k, v] of [
['page[number]', page_number_],
['page[size]', page_size_],
['filter[connection_id]', filter_connection_id_],
['filter[ip_address]', filter_ip_address_],
['filter[port]', filter_port_]
]) {
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