//native
type Telnyx = {
apiKey: string
}
/**
* Lists accounts managed by the current user.
* Lists the accounts managed by the current user. Users need to be explictly approved by Telnyx in order to become manager accounts.
*/
export async function main(
auth: Telnyx,
page_number_: string | undefined,
page_size_: string | undefined,
filter_email__contains_: string | undefined,
filter_email__eq_: string | undefined,
filter_organization_name__contains_: string | undefined,
filter_organization_name__eq_: string | undefined,
sort: 'asc' | 'desc' | undefined,
include_cancelled_accounts: string | undefined
) {
const url = new URL(`https://api.telnyx.com/v2/managed_accounts`)
for (const [k, v] of [
['page[number]', page_number_],
['page[size]', page_size_],
['filter[email][contains]', filter_email__contains_],
['filter[email][eq]', filter_email__eq_],
['filter[organization_name][contains]', filter_organization_name__contains_],
['filter[organization_name][eq]', filter_organization_name__eq_],
['sort', sort],
['include_cancelled_accounts', include_cancelled_accounts]
]) {
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