Edits history of script submission #13284 for ' Global IP Latency Metrics (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Global IP Latency Metrics
     *
     */
    export async function main(
    	auth: Telnyx,
    	filter_global_ip_id__in_: string | undefined,
    	filter_timestamp__gt_: string | undefined,
    	filter_timestamp__lt_: string | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/global_ip_latency`)
    	for (const [k, v] of [
    		['filter[global_ip_id][in]', filter_global_ip_id__in_],
    		['filter[timestamp][gt]', filter_timestamp__gt_],
    		['filter[timestamp][lt]', filter_timestamp__lt_]
    	]) {
    		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