//native
type Telnyx = {
apiKey: string
}
/**
* Get all SIM cards
* Get all SIM cards belonging to the user that match the given filters.
*/
export async function main(
auth: Telnyx,
page_number_: string | undefined,
page_size_: string | undefined,
include_sim_card_group: string | undefined,
filter_sim_card_group_id_: string | undefined,
filter_tags_: string | undefined,
filter_iccid_: string | undefined,
filter_status_: string | undefined,
sort: 'current_billing_period_consumed_data.amount' | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/sim_cards`)
for (const [k, v] of [
['page[number]', page_number_],
['page[size]', page_size_],
['include_sim_card_group', include_sim_card_group],
['filter[sim_card_group_id]', filter_sim_card_group_id_],
['filter[tags]', filter_tags_],
['filter[iccid]', filter_iccid_],
['filter[status]', filter_status_],
['sort', sort]
]) {
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