Edits history of script submission #13087 for ' Create an inventory coverage request (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Create an inventory coverage request
     * Creates an inventory coverage request. If locality, npa or national_destination_code is used in groupBy, and no region or locality filters are used, the whole paginated set is returned.
     */
    export async function main(
    	auth: Telnyx,
    	filter_npa_: string | undefined,
    	filter_nxx_: string | undefined,
    	filter_administrative_area_: string | undefined,
    	filter_phone_number_type_:
    		| 'local'
    		| 'toll_free'
    		| 'national'
    		| 'mobile'
    		| 'landline'
    		| 'shared_cost'
    		| undefined,
    	filter_country_code_:
    		| 'AT'
    		| 'AU'
    		| 'BE'
    		| 'BG'
    		| 'CA'
    		| 'CH'
    		| 'CN'
    		| 'CY'
    		| 'CZ'
    		| 'DE'
    		| 'DK'
    		| 'EE'
    		| 'ES'
    		| 'FI'
    		| 'FR'
    		| 'GB'
    		| 'GR'
    		| 'HU'
    		| 'HR'
    		| 'IE'
    		| 'IT'
    		| 'LT'
    		| 'LU'
    		| 'LV'
    		| 'NL'
    		| 'NZ'
    		| 'MX'
    		| 'NO'
    		| 'PL'
    		| 'PT'
    		| 'RO'
    		| 'SE'
    		| 'SG'
    		| 'SI'
    		| 'SK'
    		| 'US'
    		| undefined,
    	filter_count_: string | undefined,
    	filter_features_: string | undefined,
    	filter_groupBy_: 'locality' | 'npa' | 'national_destination_code' | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/inventory_coverage`)
    	for (const [k, v] of [
    		['filter[npa]', filter_npa_],
    		['filter[nxx]', filter_nxx_],
    		['filter[administrative_area]', filter_administrative_area_],
    		['filter[phone_number_type]', filter_phone_number_type_],
    		['filter[country_code]', filter_country_code_],
    		['filter[count]', filter_count_],
    		['filter[features]', filter_features_],
    		['filter[groupBy]', filter_groupBy_]
    	]) {
    		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