Edits history of script submission #11153 for ' Merge a lead and a user (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Merge a lead and a user
     * You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`.
     */
    export async function main(auth: Intercom, body: { from?: string; into?: string }) {
    	const url = new URL(`https://api.intercom.io/contacts/merge`)
    
    	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