1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a vendor credit |
7 | * Create a vendor credit for a vendor. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | ignore_auto_number_generation: string | undefined, |
13 | bill_id: string | undefined, |
14 | body: { |
15 | vendor_id: string; |
16 | vat_treatment?: string; |
17 | vendor_credit_number?: string; |
18 | gst_treatment?: string; |
19 | tax_treatment?: string; |
20 | gst_no?: string; |
21 | source_of_supply?: string; |
22 | destination_of_supply?: string; |
23 | place_of_supply?: string; |
24 | pricebook_id?: string; |
25 | reference_number?: string; |
26 | is_update_customer?: false | true; |
27 | date?: string; |
28 | exchange_rate?: number; |
29 | is_inclusive_tax?: false | true; |
30 | location_id?: string; |
31 | line_items?: { |
32 | item_id?: string; |
33 | line_item_id?: string; |
34 | account_id?: string; |
35 | name?: string; |
36 | hsn_or_sac?: string; |
37 | reverse_charge_tax_id?: string; |
38 | location_id?: string; |
39 | description?: string; |
40 | item_order?: number; |
41 | quantity?: number; |
42 | unit?: string; |
43 | rate?: number; |
44 | tax_id?: string; |
45 | tds_tax_id?: string; |
46 | tax_treatment_code?: string; |
47 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
48 | item_custom_fields?: { |
49 | custom_field_id?: number; |
50 | label?: string; |
51 | value?: string; |
52 | index?: number; |
53 | }[]; |
54 | serial_numbers?: string[]; |
55 | project_id?: string; |
56 | project_name?: string; |
57 | }[]; |
58 | notes?: string; |
59 | documents?: { document_id?: number; file_name?: string }[]; |
60 | custom_fields?: { |
61 | custom_field_id?: number; |
62 | label?: string; |
63 | value?: string; |
64 | index?: number; |
65 | }[]; |
66 | }, |
67 | ) { |
68 | const url = new URL(`https://www.zohoapis.com/inventory/v1/vendorcredits`); |
69 | for (const [k, v] of [ |
70 | ["organization_id", organization_id], |
71 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
72 | ["bill_id", bill_id], |
73 | ]) { |
74 | if (v !== undefined && v !== "" && k !== undefined) { |
75 | url.searchParams.append(k, v); |
76 | } |
77 | } |
78 | const response = await fetch(url, { |
79 | method: "POST", |
80 | headers: { |
81 | "Content-Type": "application/json", |
82 | Authorization: "Zoho-oauthtoken " + auth.token, |
83 | }, |
84 | body: JSON.stringify(body), |
85 | }); |
86 | if (!response.ok) { |
87 | const text = await response.text(); |
88 | throw new Error(`${response.status} ${text}`); |
89 | } |
90 | return await response.json(); |
91 | } |
92 |
|