0

Update an article

by
Published Dec 20, 2024

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

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