Edits history of script submission #11188 for ' Update a contact (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Update a contact
     * You can update an existing contact (ie. user or lead).
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	body: {
    		role?: string
    		external_id?: string
    		email?: string
    		phone?: string
    		name?: string
    		avatar?: string
    		signed_up_at?: number
    		last_seen_at?: number
    		owner_id?: number
    		unsubscribed_from_emails?: false | true
    		custom_attributes?: {}
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/contacts/${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