1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update email draft |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _module: string, |
12 | record: string, |
13 | draft: string, |
14 | body: { |
15 | __email_drafts: { |
16 | id: string; |
17 | modified_time: string; |
18 | created_time: string; |
19 | from: string; |
20 | to: { user_name: string; email: string }[]; |
21 | reply_to: string; |
22 | cc: { user_name: string; email: string }[]; |
23 | bcc: { user_name: string; email: string }[]; |
24 | template: { id: string; name: string }; |
25 | inventory_details: { |
26 | inventory_template: { name: string; id: string }; |
27 | record: { |
28 | id?: string; |
29 | Created_By?: { name: string; id: string; email?: string }; |
30 | Created_Time?: string; |
31 | Modified_By?: { name: string; id: string; email?: string }; |
32 | Modified_Time?: string; |
33 | Tag?: { |
34 | name: string; |
35 | color_code: |
36 | | "#57B1FD" |
37 | | "#879BFC" |
38 | | "#658BA8" |
39 | | "#FD87BD" |
40 | | "#969696" |
41 | | "#F48435" |
42 | | "#1DB9B4" |
43 | | "#E7A826" |
44 | | "#63C57E" |
45 | | "#F17574" |
46 | | "#D297EE" |
47 | | "#A8C026" |
48 | | "#B88562"; |
49 | created_time: string; |
50 | modified_time: string; |
51 | modified_by: { name: string; id: string; email?: string }; |
52 | created_by: { name: string; id: string; email?: string }; |
53 | id: string; |
54 | }[]; |
55 | name?: string; |
56 | }; |
57 | paper_type: string; |
58 | view_type: string; |
59 | }; |
60 | attachments: { service_name: string; file_size: string }[]; |
61 | schedule_details: { time: string }; |
62 | rich_text: false | true; |
63 | email_opt_out: false | true; |
64 | subject: string; |
65 | content: string; |
66 | summary: string; |
67 | }[]; |
68 | }, |
69 | ) { |
70 | const url = new URL( |
71 | `https://zohoapis.com/crm/v8/${_module}/${record}/__email_drafts/${draft}`, |
72 | ); |
73 |
|
74 | const response = await fetch(url, { |
75 | method: "PUT", |
76 | headers: { |
77 | "Content-Type": "application/json", |
78 | Authorization: "Zoho-oauthtoken " + auth.token, |
79 | }, |
80 | body: JSON.stringify(body), |
81 | }); |
82 | if (!response.ok) { |
83 | const text = await response.text(); |
84 | throw new Error(`${response.status} ${text}`); |
85 | } |
86 | return await response.json(); |
87 | } |
88 |
|