1 | type Zendesk = { |
2 | username: string; |
3 | password: string; |
4 | subdomain: string; |
5 | }; |
6 | |
7 | * Create Bookmark |
8 | * #### Allowed For |
9 | - Agents |
10 | */ |
11 | export async function main( |
12 | auth: Zendesk, |
13 | body: { |
14 | bookmark?: { ticket_id?: string; [k: string]: unknown }; |
15 | [k: string]: unknown; |
16 | } |
17 | ) { |
18 | const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/bookmarks`); |
19 |
|
20 | const response = await fetch(url, { |
21 | method: "POST", |
22 | headers: { |
23 | "Content-Type": "application/json", |
24 | Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`), |
25 | }, |
26 | body: JSON.stringify(body), |
27 | }); |
28 | if (!response.ok) { |
29 | const text = await response.text(); |
30 | throw new Error(`${response.status} ${text}`); |
31 | } |
32 | return await response.json(); |
33 | } |
34 |
|