0

Update a data attribute

by
Published Dec 20, 2024

You can update a data attribute. > 🚧 Updating the data type is not possible > > It is currently a dangerous action to execute changing a data attribute's type via the API. You will need to update the type via the UI instead.

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 data attribute
8
 * 
9
You can update a data attribute.
10

11
> 🚧 Updating the data type is not possible
12
>
13
> It is currently a dangerous action to execute changing a data attribute's type via the API. You will need to update the type via the UI instead.
14

15
 */
16
export async function main(
17
	auth: Intercom,
18
	id: string,
19
	body: {
20
		archived?: false | true
21
		description?: string
22
		options?: string[]
23
		messenger_writable?: false | true
24
	}
25
) {
26
	const url = new URL(`https://api.intercom.io/data_attributes/${id}`)
27

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