1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update Article |
7 | * Updates an article. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | id: string, |
12 | body: { |
13 | category?: string; |
14 | categories?: { id: string }[]; |
15 | knowledgeBases?: { id: string; featured: false | true }[]; |
16 | tags?: string[]; |
17 | scope?: "public" | "internal"; |
18 | published?: false | true; |
19 | externalId?: string; |
20 | deleted?: true; |
21 | }, |
22 | ) { |
23 | const url = new URL(`https://api.kustomerapp.com/v1/kb/articles/${id}`); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "PUT", |
27 | headers: { |
28 | "Content-Type": "application/json", |
29 | Authorization: "Bearer " + auth.apiKey, |
30 | }, |
31 | body: JSON.stringify(body), |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.json(); |
38 | } |
39 |
|