0

Retrieve a Quote

by
Published Oct 17, 2025

Fetch the details of a quote.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Retrieve a Quote
7
 * Fetch the details of a quote.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  estimate_id: string,
12
  print: string | undefined,
13
  accept: string | undefined,
14
  X_com_zoho_subscriptions_organizationid: string,
15
) {
16
  const url = new URL(
17
    `https://www.zohoapis.com/billing/v1/estimates/${estimate_id}`,
18
  );
19
  for (const [k, v] of [
20
    ["print", print],
21
    ["accept", accept],
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
      "X-com-zoho-subscriptions-organizationid":
31
        X_com_zoho_subscriptions_organizationid,
32
      Authorization: "Zoho-oauthtoken " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42