Edits history of script submission #11097 for ' Convert a conversation to a ticket (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Convert a conversation to a ticket
     * You can convert a conversation to a ticket.
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	body: { ticket_type_id: string; attributes?: {} }
    ) {
    	const url = new URL(`https://api.intercom.io/conversations/${id}/convert`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		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 537 days ago