0

Create a Currency

by
Published Oct 17, 2025

Create a currency for transaction.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Create a Currency
7
 * Create a currency for transaction.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    currency_code: string;
14
    currency_symbol: string;
15
    price_precision?: number;
16
    currency_format?: string;
17
  },
18
) {
19
  const url = new URL(
20
    `https://www.zohoapis.com/inventory/v1/settings/currencies`,
21
  );
22
  for (const [k, v] of [["organization_id", organization_id]]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "POST",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Zoho-oauthtoken " + auth.token,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41