Edits history of script submission #13319 for ' List all External Connections (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * List all External Connections
     * This endpoint returns a list of your External Connections inside the 'data' attribute of the response. External Connections are used by Telnyx customers to seamless configure SIP trunking integrations with Telnyx Partners, through External Voice Integrations in Mission Control Portal.
     */
    export async function main(
    	auth: Telnyx,
    	page_number_: string | undefined,
    	page_size_: string | undefined,
    	filter_connection_name__contains_: string | undefined,
    	filter_external_sip_connection_: 'zoom' | 'operator_connect' | undefined,
    	filter_id_: string | undefined,
    	filter_created_at_: string | undefined,
    	filter_phone_number__contains_: string | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/external_connections`)
    	for (const [k, v] of [
    		['page[number]', page_number_],
    		['page[size]', page_size_],
    		['filter[connection_name][contains]', filter_connection_name__contains_],
    		['filter[external_sip_connection]', filter_external_sip_connection_],
    		['filter[id]', filter_id_],
    		['filter[created_at]', filter_created_at_],
    		['filter[phone_number][contains]', filter_phone_number__contains_]
    	]) {
    		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