Edits history of script submission #11090 for ' Add tag to a contact (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Add tag to a contact
     * You can tag a specific contact. This will return a tag object for the tag that was added to the contact.
     */
    export async function main(auth: Intercom, contact_id: string, body: { id: string }) {
    	const url = new URL(`https://api.intercom.io/contacts/${contact_id}/tags`)
    
    	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