0

List all articles

by
Published Dec 20, 2024

You can fetch a list of all articles by making a GET request to `https://api.intercom.io/articles`. > 📘 How are the articles sorted and ordered? > > Articles will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated articles first.

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 articles
8
 * You can fetch a list of all articles by making a GET request to `https://api.intercom.io/articles`.
9

10
> 📘 How are the articles sorted and ordered?
11
>
12
> Articles will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated articles first.
13

14
 */
15
export async function main(auth: Intercom) {
16
	const url = new URL(`https://api.intercom.io/articles`)
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