1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List credit note refunds |
7 | * List all refunds with pagination. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | customer_id: string | undefined, |
13 | sort_column: string | undefined, |
14 | ) { |
15 | const url = new URL( |
16 | `https://www.zohoapis.com/inventory/v1/creditnotes/refunds`, |
17 | ); |
18 | for (const [k, v] of [ |
19 | ["organization_id", organization_id], |
20 | ["customer_id", customer_id], |
21 | ["sort_column", sort_column], |
22 | ]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "GET", |
29 | headers: { |
30 | Authorization: "Zoho-oauthtoken " + auth.token, |
31 | }, |
32 | body: undefined, |
33 | }); |
34 | if (!response.ok) { |
35 | const text = await response.text(); |
36 | throw new Error(`${response.status} ${text}`); |
37 | } |
38 | return await response.json(); |
39 | } |
40 |
|