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