1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a credit note using a custom field's unique value |
7 | * A custom field will have unique values if it's configured to not accept duplicate values. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | X_Unique_Identifier_Key: string, |
13 | X_Unique_Identifier_Value: string, |
14 | body: { |
15 | customer_id: string; |
16 | currency_id?: string; |
17 | contact_persons?: string[]; |
18 | date: string; |
19 | is_draft?: false | true; |
20 | exchange_rate?: string; |
21 | line_items: { |
22 | item_id?: string; |
23 | line_item_id?: string; |
24 | account_id?: string; |
25 | name?: string; |
26 | description?: string; |
27 | item_order?: number; |
28 | rate?: number; |
29 | quantity?: number; |
30 | unit?: string; |
31 | discount?: number; |
32 | tax_id?: string; |
33 | tds_tax_id?: string; |
34 | tax_exemption_id?: string; |
35 | tax_exemption_code?: string; |
36 | tax_treatment_code?: string; |
37 | avatax_use_code?: string; |
38 | avatax_tax_code?: string; |
39 | product_type?: string; |
40 | hsn_or_sac?: string; |
41 | sat_item_key_code?: string; |
42 | unitkey_code?: string; |
43 | item_custom_fields?: string[]; |
44 | location_id?: string; |
45 | location_name?: string; |
46 | serial_numbers?: string; |
47 | project_id?: string; |
48 | }[]; |
49 | location_id?: string; |
50 | creditnote_number: string; |
51 | gst_treatment?: string; |
52 | tax_treatment?: string; |
53 | is_reverse_charge_applied?: false | true; |
54 | gst_no?: string; |
55 | cfdi_usage?: string; |
56 | cfdi_reference_type?: string; |
57 | place_of_supply?: string; |
58 | ignore_auto_number_generation?: false | true; |
59 | reference_number?: string; |
60 | custom_fields?: string[]; |
61 | notes?: string; |
62 | terms?: string; |
63 | template_id?: string; |
64 | tax_id?: string; |
65 | tax_authority_id?: string; |
66 | tax_exemption_id?: string; |
67 | avatax_use_code?: string; |
68 | avatax_exempt_no?: string; |
69 | vat_treatment?: string; |
70 | is_inclusive_tax?: false | true; |
71 | item_id?: string; |
72 | account_id?: string; |
73 | name?: string; |
74 | avatax_tax_code?: string; |
75 | description?: string; |
76 | unit?: string; |
77 | rate?: number; |
78 | quantity?: number; |
79 | }, |
80 | X_Upsert?: string, |
81 | ) { |
82 | const url = new URL(`https://www.zohoapis.com/books/v3/creditnotes`); |
83 | for (const [k, v] of [["organization_id", organization_id]]) { |
84 | if (v !== undefined && v !== "" && k !== undefined) { |
85 | url.searchParams.append(k, v); |
86 | } |
87 | } |
88 | const response = await fetch(url, { |
89 | method: "PUT", |
90 | headers: { |
91 | "X-Unique-Identifier-Key": X_Unique_Identifier_Key, |
92 | "X-Unique-Identifier-Value": X_Unique_Identifier_Value, |
93 | ...(X_Upsert ? { "X-Upsert": X_Upsert } : {}), |
94 | "Content-Type": "application/json", |
95 | Authorization: "Zoho-oauthtoken " + auth.token, |
96 | }, |
97 | body: JSON.stringify(body), |
98 | }); |
99 | if (!response.ok) { |
100 | const text = await response.text(); |
101 | throw new Error(`${response.status} ${text}`); |
102 | } |
103 | return await response.json(); |
104 | } |
105 |
|