0

Create or Update a company

by
Published Dec 20, 2024

You can create or update a company.

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
 * Create or Update a company
8
 * You can create or update a company.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	body: {
13
		name?: string
14
		company_id?: string
15
		plan?: string
16
		size?: number
17
		website?: string
18
		industry?: string
19
		custom_attributes?: {}
20
		remote_created_at?: number
21
		monthly_spend?: number
22
	}
23
) {
24
	const url = new URL(`https://api.intercom.io/companies`)
25

26
	const response = await fetch(url, {
27
		method: 'POST',
28
		headers: {
29
			'Intercom-Version': auth.apiVersion,
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41