1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a sales order 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 | shipment_date?: string; |
20 | custom_fields?: { customfield_id?: number; value?: string }[]; |
21 | place_of_supply?: string; |
22 | salesperson_id?: string; |
23 | merchant_id?: string; |
24 | gst_treatment?: string; |
25 | gst_no?: string; |
26 | is_inclusive_tax?: false | true; |
27 | location_id?: string; |
28 | line_items?: { |
29 | item_order?: number; |
30 | line_item_id?: string; |
31 | item_id?: string; |
32 | rate?: number; |
33 | name?: string; |
34 | description?: string; |
35 | quantity?: number; |
36 | discount?: string; |
37 | tax_id?: string; |
38 | tds_tax_id?: string; |
39 | tags?: { tag_id?: string; tag_option_id?: string }[]; |
40 | unit?: string; |
41 | item_custom_fields?: { customfield_id?: number; value?: string }[]; |
42 | tax_exemption_id?: string; |
43 | tax_exemption_code?: string; |
44 | tax_treatment_code?: string; |
45 | avatax_exempt_no?: string; |
46 | avatax_use_code?: string; |
47 | project_id?: string; |
48 | location_id?: string; |
49 | }[]; |
50 | notes?: string; |
51 | terms?: string; |
52 | billing_address_id?: string; |
53 | shipping_address_id?: string; |
54 | crm_owner_id?: string; |
55 | crm_custom_reference_id?: string; |
56 | vat_treatment?: string; |
57 | tax_treatment?: string; |
58 | is_reverse_charge_applied?: false | true; |
59 | salesorder_number?: string; |
60 | reference_number?: string; |
61 | is_update_customer?: false | true; |
62 | discount?: string; |
63 | exchange_rate?: number; |
64 | salesperson_name?: string; |
65 | notes_default?: string; |
66 | terms_default?: string; |
67 | tax_id?: string; |
68 | tax_authority_id?: string; |
69 | tax_exemption_id?: string; |
70 | tax_authority_name?: string; |
71 | tax_exemption_code?: string; |
72 | avatax_exempt_no?: string; |
73 | avatax_use_code?: string; |
74 | shipping_charge?: number; |
75 | adjustment?: number; |
76 | delivery_method?: string; |
77 | is_discount_before_tax?: false | true; |
78 | discount_type?: string; |
79 | adjustment_description?: string; |
80 | pricebook_id?: string; |
81 | template_id?: string; |
82 | documents?: string[]; |
83 | zcrm_potential_id?: string; |
84 | zcrm_potential_name?: string; |
85 | }, |
86 | X_Upsert?: string, |
87 | ) { |
88 | const url = new URL(`https://www.zohoapis.com/books/v3/salesorders`); |
89 | for (const [k, v] of [["organization_id", organization_id]]) { |
90 | if (v !== undefined && v !== "" && k !== undefined) { |
91 | url.searchParams.append(k, v); |
92 | } |
93 | } |
94 | const response = await fetch(url, { |
95 | method: "PUT", |
96 | headers: { |
97 | "X-Unique-Identifier-Key": X_Unique_Identifier_Key, |
98 | "X-Unique-Identifier-Value": X_Unique_Identifier_Value, |
99 | ...(X_Upsert ? { "X-Upsert": X_Upsert } : {}), |
100 | "Content-Type": "application/json", |
101 | Authorization: "Zoho-oauthtoken " + auth.token, |
102 | }, |
103 | body: JSON.stringify(body), |
104 | }); |
105 | if (!response.ok) { |
106 | const text = await response.text(); |
107 | throw new Error(`${response.status} ${text}`); |
108 | } |
109 | return await response.json(); |
110 | } |
111 |
|