Edits history of script submission #11091 for ' Add tag to a conversation (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 conversation
     * You can tag a specific conversation. This will return a tag object for the tag that was added to the conversation.
     */
    export async function main(
    	auth: Intercom,
    	conversation_id: string,
    	body: { id: string; admin_id: string }
    ) {
    	const url = new URL(`https://api.intercom.io/conversations/${conversation_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 536 days ago