You can fetch a list of segments that are associated to a contact.
1
//native
2
type Intercom = {
3
apiVersion: string
4
token: string
5
}
6
/**
7
* List attached segments for contact
8
* You can fetch a list of segments that are associated to a contact.
9
*/
10
export async function main(auth: Intercom, contact_id: string) {
11
const url = new URL(`https://api.intercom.io/contacts/${contact_id}/segments`)
12
13
const response = await fetch(url, {
14
method: 'GET',
15
headers: {
16
'Intercom-Version': auth.apiVersion,
17
Authorization: 'Bearer ' + auth.token
18
},
19
body: undefined
20
})
21
if (!response.ok) {
22
const text = await response.text()
23
throw new Error(`${response.status} ${text}`)
24
25
return await response.json()
26
27