Edits history of script submission #11112 for ' Create or Update a company (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 company
     * You can create or update a company.
     */
    export async function main(
    	auth: Intercom,
    	body: {
    		name?: string
    		company_id?: string
    		plan?: string
    		size?: number
    		website?: string
    		industry?: string
    		custom_attributes?: {}
    		remote_created_at?: number
    		monthly_spend?: number
    	}
    ) {
    	const url = new URL(`https://api.intercom.io/companies`)
    
    	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