Edits history of script submission #11111 for ' Create event summaries (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Create event summaries
     * Create event summaries for a user. Event summaries are used to track the number of times an event has occurred, the first time it occurred and the last time it occurred.
    
    
     */
    export async function main(
    	auth: Intercom,
    	body: {
    		user_id?: string
    		event_summaries?: {
    			event_name?: string
    			count?: number
    			first?: number
    			last?: number
    		}
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/events/summaries`)
    
    	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.text()
    }
    

    Submitted by hugo697 537 days ago