1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a pricebook |
7 | * create a new pricebook. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | name: string; |
14 | description?: string; |
15 | currency_id: string; |
16 | pricebook_type: string; |
17 | is_increase: false | true; |
18 | rounding_type?: string; |
19 | pricebook_items?: { item_id?: number; pricebook_rate?: number }[]; |
20 | sales_or_purchase_type: string; |
21 | }, |
22 | ) { |
23 | const url = new URL(`https://www.zohoapis.com/inventory/v1/pricebooks`); |
24 | for (const [k, v] of [["organization_id", organization_id]]) { |
25 | if (v !== undefined && v !== "" && k !== undefined) { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "POST", |
31 | headers: { |
32 | "Content-Type": "application/json", |
33 | Authorization: "Zoho-oauthtoken " + auth.token, |
34 | }, |
35 | body: JSON.stringify(body), |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|