You can attach a company to a single contact.
1
//native
2
type Intercom = {
3
apiVersion: string
4
token: string
5
}
6
/**
7
* Attach a Contact to a Company
8
* You can attach a company to a single contact.
9
*/
10
export async function main(auth: Intercom, id: string, body: { id: string }) {
11
const url = new URL(`https://api.intercom.io/contacts/${id}/companies`)
12
13
const response = await fetch(url, {
14
method: 'POST',
15
headers: {
16
'Intercom-Version': auth.apiVersion,
17
'Content-Type': 'application/json',
18
Authorization: 'Bearer ' + auth.token
19
},
20
body: JSON.stringify(body)
21
})
22
if (!response.ok) {
23
const text = await response.text()
24
throw new Error(`${response.status} ${text}`)
25
26
return await response.json()
27
28