Edits history of script submission #11196 for ' Update an existing attribute for a ticket type (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Update an existing attribute for a ticket type
     * You can update an existing attribute for a ticket type.
     */
    export async function main(
    	auth: Intercom,
    	ticket_type_id: string,
    	id: string,
    	body: {
    		name?: string
    		description?: string
    		required_to_create?: false | true
    		required_to_create_for_contacts?: false | true
    		visible_on_create?: false | true
    		visible_to_contacts?: false | true
    		multiline?: false | true
    		list_items?: string
    		allow_multiple_values?: false | true
    		archived?: false | true
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/ticket_types/${ticket_type_id}/attributes/${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