//native
type Telnyx = {
apiKey: string
}
/**
* Get all SIM card orders
* Get all SIM card orders according to filters.
*/
export async function main(
auth: Telnyx,
filter_created_at_: string | undefined,
filter_updated_at_: string | undefined,
filter_quantity_: string | undefined,
filter_cost_amount_: string | undefined,
filter_cost_currency_: string | undefined,
filter_address_id_: string | undefined,
filter_address_street_address_: string | undefined,
filter_address_extended_address_: string | undefined,
filter_address_locality_: string | undefined,
filter_address_administrative_area_: string | undefined,
filter_address_country_code_: string | undefined,
filter_address_postal_code_: string | undefined,
page_number_: string | undefined,
page_size_: string | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/sim_card_orders`)
for (const [k, v] of [
['filter[created_at]', filter_created_at_],
['filter[updated_at]', filter_updated_at_],
['filter[quantity]', filter_quantity_],
['filter[cost.amount]', filter_cost_amount_],
['filter[cost.currency]', filter_cost_currency_],
['filter[address.id]', filter_address_id_],
['filter[address.street_address]', filter_address_street_address_],
['filter[address.extended_address]', filter_address_extended_address_],
['filter[address.locality]', filter_address_locality_],
['filter[address.administrative_area]', filter_address_administrative_area_],
['filter[address.country_code]', filter_address_country_code_],
['filter[address.postal_code]', filter_address_postal_code_],
['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