0

List all contacts

by
Published Dec 20, 2024

You can fetch a list of all contacts (ie. users or leads) in your workspace. {% admonition type="warning" name="Pagination" %} You can use pagination to limit the number of results returned. The default is `50` results per page. See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. {% /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
 * List all contacts
8
 * You can fetch a list of all contacts (ie. users or leads) in your workspace.
9
{% admonition type="warning" name="Pagination" %}
10
  You can use pagination to limit the number of results returned. The default is `50` results per page.
11
  See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param.
12
{% /admonition %}
13

14
 */
15
export async function main(auth: Intercom) {
16
	const url = new URL(`https://api.intercom.io/contacts`)
17

18
	const response = await fetch(url, {
19
		method: 'GET',
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