0

Update a company

by
Published Dec 20, 2024

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 %}

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * Update a company
8
 * You can update a single company using the Intercom provisioned `id`.
9

10
{% admonition type="attention" name="Using `company_id`" %}
11
  When updating a company it is not possible to update `company_id`. This can only be set once upon creation of the company.
12
{% /admonition %}
13

14
 */
15
export async function main(auth: Intercom, id: string) {
16
	const url = new URL(`https://api.intercom.io/companies/${id}`)
17

18
	const response = await fetch(url, {
19
		method: 'PUT',
20
		headers: {
21
			'Intercom-Version': auth.apiVersion,
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: undefined
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32