Edits history of script submission #11187 for ' Update a company (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Update a company
     * You can update a single company using the Intercom provisioned `id`.
    
    {% admonition type="attention" name="Using `company_id`" %}
      When updating a company it is not possible to update `company_id`. This can only be set once upon creation of the company.
    {% /admonition %}
    
     */
    export async function main(auth: Intercom, id: string) {
    	const url = new URL(`https://api.intercom.io/companies/${id}`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Intercom-Version': auth.apiVersion,
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 536 days ago