Edits history of script submission #13009 for ' Assign a phone number to a channel zone (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Assign a phone number to a channel zone
     * You should own the phone number being assigned to the channel zone. Remember that you should reserve channels in this channel zone, otherwise you won't be able to receive incoming calls.
     */
    export async function main(auth: Telnyx, channel_zone_id: string, body: { phone_number: string }) {
    	const url = new URL(
    		`https://api.telnyx.com/v2/channel_zones/${channel_zone_id}/channel_zone_phone_numbers`
    	)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		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