Edits history of script submission #13612 for ' Update a notification channel (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Update a notification channel
     * Update a notification channel.
     */
    export async function main(
    	auth: Telnyx,
    	id: string,
    	body: {
    		id?: string
    		notification_profile_id?: string
    		channel_type_id?: 'sms' | 'voice' | 'email' | 'webhook'
    		channel_destination?: string
    		created_at?: string
    		updated_at?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/notification_channels/${id}`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago