0

Download content data export

by
Published Dec 20, 2024

When a job has a status of complete, and thus a filled download_url, you can download your data by hitting that provided URL, formatted like so: https://api.intercom.io/download/content/data/xyz1234. Your exported message data will be streamed continuously back down to you in a gzipped CSV format. > 📘 Octet header required > > You will have to specify the header Accept: `application/octet-stream` when hitting this endpoint.

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
 * Download content data export
8
 * When a job has a status of complete, and thus a filled download_url, you can download your data by hitting that provided URL, formatted like so: https://api.intercom.io/download/content/data/xyz1234.
9

10
Your exported message data will be streamed continuously back down to you in a gzipped CSV format.
11

12
> 📘 Octet header required
13
>
14
> You will have to specify the header Accept: `application/octet-stream` when hitting this endpoint.
15

16
 */
17
export async function main(auth: Intercom, job_identifier: string) {
18
	const url = new URL(`https://api.intercom.io/download/content/data/${job_identifier}`)
19

20
	const response = await fetch(url, {
21
		method: 'GET',
22
		headers: {
23
			'Intercom-Version': auth.apiVersion,
24
			Authorization: 'Bearer ' + auth.token
25
		},
26
		body: undefined
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.text()
33
}
34