0

Create an article

by
Published Dec 20, 2024

You can create a new article by making a POST request to `https://api.intercom.io/articles`.

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 an article
8
 * You can create a new article by making a POST request to `https://api.intercom.io/articles`.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	body: {
13
		title: string
14
		description?: string
15
		body?: string
16
		author_id: number
17
		state?: 'published' | 'draft'
18
		parent_id?: number
19
		parent_type?: string
20
		translated_content?: {
21
			type?: 'article_translated_content'
22
			ar?: {
23
				type?: 'article_content'
24
				title?: string
25
				description?: string
26
				body?: string
27
				author_id?: number
28
				state?: 'published' | 'draft'
29
				created_at?: number
30
				updated_at?: number
31
				url?: string
32
			}
33
			bg?: {
34
				type?: 'article_content'
35
				title?: string
36
				description?: string
37
				body?: string
38
				author_id?: number
39
				state?: 'published' | 'draft'
40
				created_at?: number
41
				updated_at?: number
42
				url?: string
43
			}
44
			bs?: {
45
				type?: 'article_content'
46
				title?: string
47
				description?: string
48
				body?: string
49
				author_id?: number
50
				state?: 'published' | 'draft'
51
				created_at?: number
52
				updated_at?: number
53
				url?: string
54
			}
55
			ca?: {
56
				type?: 'article_content'
57
				title?: string
58
				description?: string
59
				body?: string
60
				author_id?: number
61
				state?: 'published' | 'draft'
62
				created_at?: number
63
				updated_at?: number
64
				url?: string
65
			}
66
			cs?: {
67
				type?: 'article_content'
68
				title?: string
69
				description?: string
70
				body?: string
71
				author_id?: number
72
				state?: 'published' | 'draft'
73
				created_at?: number
74
				updated_at?: number
75
				url?: string
76
			}
77
			da?: {
78
				type?: 'article_content'
79
				title?: string
80
				description?: string
81
				body?: string
82
				author_id?: number
83
				state?: 'published' | 'draft'
84
				created_at?: number
85
				updated_at?: number
86
				url?: string
87
			}
88
			de?: {
89
				type?: 'article_content'
90
				title?: string
91
				description?: string
92
				body?: string
93
				author_id?: number
94
				state?: 'published' | 'draft'
95
				created_at?: number
96
				updated_at?: number
97
				url?: string
98
			}
99
			el?: {
100
				type?: 'article_content'
101
				title?: string
102
				description?: string
103
				body?: string
104
				author_id?: number
105
				state?: 'published' | 'draft'
106
				created_at?: number
107
				updated_at?: number
108
				url?: string
109
			}
110
			en?: {
111
				type?: 'article_content'
112
				title?: string
113
				description?: string
114
				body?: string
115
				author_id?: number
116
				state?: 'published' | 'draft'
117
				created_at?: number
118
				updated_at?: number
119
				url?: string
120
			}
121
			es?: {
122
				type?: 'article_content'
123
				title?: string
124
				description?: string
125
				body?: string
126
				author_id?: number
127
				state?: 'published' | 'draft'
128
				created_at?: number
129
				updated_at?: number
130
				url?: string
131
			}
132
			et?: {
133
				type?: 'article_content'
134
				title?: string
135
				description?: string
136
				body?: string
137
				author_id?: number
138
				state?: 'published' | 'draft'
139
				created_at?: number
140
				updated_at?: number
141
				url?: string
142
			}
143
			fi?: {
144
				type?: 'article_content'
145
				title?: string
146
				description?: string
147
				body?: string
148
				author_id?: number
149
				state?: 'published' | 'draft'
150
				created_at?: number
151
				updated_at?: number
152
				url?: string
153
			}
154
			fr?: {
155
				type?: 'article_content'
156
				title?: string
157
				description?: string
158
				body?: string
159
				author_id?: number
160
				state?: 'published' | 'draft'
161
				created_at?: number
162
				updated_at?: number
163
				url?: string
164
			}
165
			he?: {
166
				type?: 'article_content'
167
				title?: string
168
				description?: string
169
				body?: string
170
				author_id?: number
171
				state?: 'published' | 'draft'
172
				created_at?: number
173
				updated_at?: number
174
				url?: string
175
			}
176
			hr?: {
177
				type?: 'article_content'
178
				title?: string
179
				description?: string
180
				body?: string
181
				author_id?: number
182
				state?: 'published' | 'draft'
183
				created_at?: number
184
				updated_at?: number
185
				url?: string
186
			}
187
			hu?: {
188
				type?: 'article_content'
189
				title?: string
190
				description?: string
191
				body?: string
192
				author_id?: number
193
				state?: 'published' | 'draft'
194
				created_at?: number
195
				updated_at?: number
196
				url?: string
197
			}
198
			id?: {
199
				type?: 'article_content'
200
				title?: string
201
				description?: string
202
				body?: string
203
				author_id?: number
204
				state?: 'published' | 'draft'
205
				created_at?: number
206
				updated_at?: number
207
				url?: string
208
			}
209
			it?: {
210
				type?: 'article_content'
211
				title?: string
212
				description?: string
213
				body?: string
214
				author_id?: number
215
				state?: 'published' | 'draft'
216
				created_at?: number
217
				updated_at?: number
218
				url?: string
219
			}
220
			ja?: {
221
				type?: 'article_content'
222
				title?: string
223
				description?: string
224
				body?: string
225
				author_id?: number
226
				state?: 'published' | 'draft'
227
				created_at?: number
228
				updated_at?: number
229
				url?: string
230
			}
231
			ko?: {
232
				type?: 'article_content'
233
				title?: string
234
				description?: string
235
				body?: string
236
				author_id?: number
237
				state?: 'published' | 'draft'
238
				created_at?: number
239
				updated_at?: number
240
				url?: string
241
			}
242
			lt?: {
243
				type?: 'article_content'
244
				title?: string
245
				description?: string
246
				body?: string
247
				author_id?: number
248
				state?: 'published' | 'draft'
249
				created_at?: number
250
				updated_at?: number
251
				url?: string
252
			}
253
			lv?: {
254
				type?: 'article_content'
255
				title?: string
256
				description?: string
257
				body?: string
258
				author_id?: number
259
				state?: 'published' | 'draft'
260
				created_at?: number
261
				updated_at?: number
262
				url?: string
263
			}
264
			mn?: {
265
				type?: 'article_content'
266
				title?: string
267
				description?: string
268
				body?: string
269
				author_id?: number
270
				state?: 'published' | 'draft'
271
				created_at?: number
272
				updated_at?: number
273
				url?: string
274
			}
275
			nb?: {
276
				type?: 'article_content'
277
				title?: string
278
				description?: string
279
				body?: string
280
				author_id?: number
281
				state?: 'published' | 'draft'
282
				created_at?: number
283
				updated_at?: number
284
				url?: string
285
			}
286
			nl?: {
287
				type?: 'article_content'
288
				title?: string
289
				description?: string
290
				body?: string
291
				author_id?: number
292
				state?: 'published' | 'draft'
293
				created_at?: number
294
				updated_at?: number
295
				url?: string
296
			}
297
			pl?: {
298
				type?: 'article_content'
299
				title?: string
300
				description?: string
301
				body?: string
302
				author_id?: number
303
				state?: 'published' | 'draft'
304
				created_at?: number
305
				updated_at?: number
306
				url?: string
307
			}
308
			pt?: {
309
				type?: 'article_content'
310
				title?: string
311
				description?: string
312
				body?: string
313
				author_id?: number
314
				state?: 'published' | 'draft'
315
				created_at?: number
316
				updated_at?: number
317
				url?: string
318
			}
319
			ro?: {
320
				type?: 'article_content'
321
				title?: string
322
				description?: string
323
				body?: string
324
				author_id?: number
325
				state?: 'published' | 'draft'
326
				created_at?: number
327
				updated_at?: number
328
				url?: string
329
			}
330
			ru?: {
331
				type?: 'article_content'
332
				title?: string
333
				description?: string
334
				body?: string
335
				author_id?: number
336
				state?: 'published' | 'draft'
337
				created_at?: number
338
				updated_at?: number
339
				url?: string
340
			}
341
			sl?: {
342
				type?: 'article_content'
343
				title?: string
344
				description?: string
345
				body?: string
346
				author_id?: number
347
				state?: 'published' | 'draft'
348
				created_at?: number
349
				updated_at?: number
350
				url?: string
351
			}
352
			sr?: {
353
				type?: 'article_content'
354
				title?: string
355
				description?: string
356
				body?: string
357
				author_id?: number
358
				state?: 'published' | 'draft'
359
				created_at?: number
360
				updated_at?: number
361
				url?: string
362
			}
363
			sv?: {
364
				type?: 'article_content'
365
				title?: string
366
				description?: string
367
				body?: string
368
				author_id?: number
369
				state?: 'published' | 'draft'
370
				created_at?: number
371
				updated_at?: number
372
				url?: string
373
			}
374
			tr?: {
375
				type?: 'article_content'
376
				title?: string
377
				description?: string
378
				body?: string
379
				author_id?: number
380
				state?: 'published' | 'draft'
381
				created_at?: number
382
				updated_at?: number
383
				url?: string
384
			}
385
			vi?: {
386
				type?: 'article_content'
387
				title?: string
388
				description?: string
389
				body?: string
390
				author_id?: number
391
				state?: 'published' | 'draft'
392
				created_at?: number
393
				updated_at?: number
394
				url?: string
395
			}
396
			'pt-BR'?: {
397
				type?: 'article_content'
398
				title?: string
399
				description?: string
400
				body?: string
401
				author_id?: number
402
				state?: 'published' | 'draft'
403
				created_at?: number
404
				updated_at?: number
405
				url?: string
406
			}
407
			'zh-CN'?: {
408
				type?: 'article_content'
409
				title?: string
410
				description?: string
411
				body?: string
412
				author_id?: number
413
				state?: 'published' | 'draft'
414
				created_at?: number
415
				updated_at?: number
416
				url?: string
417
			}
418
			'zh-TW'?: {
419
				type?: 'article_content'
420
				title?: string
421
				description?: string
422
				body?: string
423
				author_id?: number
424
				state?: 'published' | 'draft'
425
				created_at?: number
426
				updated_at?: number
427
				url?: string
428
			}
429
		}
430
	}
431
) {
432
	const url = new URL(`https://api.intercom.io/articles`)
433

434
	const response = await fetch(url, {
435
		method: 'POST',
436
		headers: {
437
			'Intercom-Version': auth.apiVersion,
438
			'Content-Type': 'application/json',
439
			Authorization: 'Bearer ' + auth.token
440
		},
441
		body: JSON.stringify(body)
442
	})
443
	if (!response.ok) {
444
		const text = await response.text()
445
		throw new Error(`${response.status} ${text}`)
446
	}
447
	return await response.json()
448
}
449