Edits history of script submission #11106 for ' Create a ticket (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Create a ticket
     * You can create a new ticket.
     */
    export async function main(
    	auth: Intercom,
    	body: {
    		ticket_type_id: string
    		contacts: { id: string } | { external_id: string } | { email: string }[]
    		company_id?: string
    		created_at?: number
    		ticket_attributes?: {}
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/tickets`)
    
    	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 536 days ago