1 | |
2 | type Kustomer = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Update Route |
7 | * Updates requested route. |
8 | */ |
9 | export async function main( |
10 | auth: Kustomer, |
11 | id: string, |
12 | body: {} & { |
13 | url?: string; |
14 | routableType?: "article" | "category"; |
15 | routableId?: string; |
16 | pattern?: string; |
17 | position?: number; |
18 | }, |
19 | ) { |
20 | const url = new URL(`https://api.kustomerapp.com/v1/kb/routes/${id}`); |
21 |
|
22 | const response = await fetch(url, { |
23 | method: "PUT", |
24 | headers: { |
25 | "Content-Type": "application/json", |
26 | Authorization: "Bearer " + auth.apiKey, |
27 | }, |
28 | body: JSON.stringify(body), |
29 | }); |
30 | if (!response.ok) { |
31 | const text = await response.text(); |
32 | throw new Error(`${response.status} ${text}`); |
33 | } |
34 | return await response.json(); |
35 | } |
36 |
|