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