Edits history of script submission #11193 for ' Update a ticket type (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Update a ticket type
     * 
    You can update a ticket type.
    
    > 📘 Updating a ticket type.
    >
    > For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/)
    
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	body: {
    		name?: string
    		description?: string
    		category?: 'Customer' | 'Back-office' | 'Tracker'
    		icon?: string
    		archived?: false | true
    		is_internal?: false | true
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/ticket_types/${id}`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Intercom-Version': auth.apiVersion,
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		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 536 days ago