Edits history of script submission #11100 for ' Create a data attribute (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Create a data attribute
     * You can create a data attributes for a `contact` or a `company`.
     */
    export async function main(
    	auth: Intercom,
    	body: {
    		name: string
    		model: 'contact' | 'company'
    		data_type: 'string' | 'boolean' | 'integer' | 'float' | 'datetime' | 'date'
    		description?: string
    		options?: string[]
    		messenger_writable?: false | true
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/data_attributes`)
    
    	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