Edits history of script submission #13394 for ' List mobile network operators (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * List mobile network operators
     * Telnyx has a set of GSM mobile operators partners that are available through our mobile network roaming. This resource is entirely managed by Telnyx and may change over time. That means that this resource won't allow any write operations for it. Still, it's available so it can be used as a support resource that can be related to other resources or become a configuration option.
     */
    export async function main(
    	auth: Telnyx,
    	page_number_: string | undefined,
    	page_size_: string | undefined,
    	filter_name__starts_with_: string | undefined,
    	filter_name__contains_: string | undefined,
    	filter_name__ends_with_: string | undefined,
    	filter_country_code_: string | undefined,
    	filter_mcc_: string | undefined,
    	filter_mnc_: string | undefined,
    	filter_tadig_: string | undefined,
    	filter_network_preferences_enabled_: string | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/mobile_network_operators`)
    	for (const [k, v] of [
    		['page[number]', page_number_],
    		['page[size]', page_size_],
    		['filter[name][starts_with]', filter_name__starts_with_],
    		['filter[name][contains]', filter_name__contains_],
    		['filter[name][ends_with]', filter_name__ends_with_],
    		['filter[country_code]', filter_country_code_],
    		['filter[mcc]', filter_mcc_],
    		['filter[mnc]', filter_mnc_],
    		['filter[tadig]', filter_tadig_],
    		['filter[network_preferences_enabled]', filter_network_preferences_enabled_]
    	]) {
    		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