Edits history of script submission #11113 for ' Create or update a tag, Tag or untag companies, Tag contacts (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Create or update a tag, Tag or untag companies, Tag contacts
     * You can use this endpoint to perform the following operations:
    
      **1.
     */
    export async function main(
    	auth: Intercom,
    	body:
    		| { name: string; id?: string }
    		| { name: string; companies: { id?: string; company_id?: string }[] }
    		| {
    				name: string
    				companies: { id?: string; company_id?: string; untag?: false | true }[]
    		  }
    		| { name: string; users: { id?: string }[] }
    ) {
    	const url = new URL(`https://api.intercom.io/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