0

Create content data export

by
Published Dec 20, 2024

To create your export job, you need to send a `POST` request to the export endpoint `https://api.

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
 * Create content data export
8
 * To create your export job, you need to send a `POST` request to the export endpoint `https://api.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	body: { created_at_after: number; created_at_before: number }
13
) {
14
	const url = new URL(`https://api.intercom.io/export/content/data`)
15

16
	const response = await fetch(url, {
17
		method: 'POST',
18
		headers: {
19
			'Intercom-Version': auth.apiVersion,
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + auth.token
22
		},
23
		body: JSON.stringify(body)
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31