0

Create an item adjustment

by
Published Oct 17, 2025

Creates a new item adjustment in Zoho Inventory.

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 an item adjustment
7
 * Creates a new item adjustment in Zoho Inventory.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    date: string;
14
    reason: string;
15
    description?: string;
16
    reference_number?: string;
17
    adjustment_type: "quantity";
18
    location_id?: string;
19
    line_items: {
20
      item_id: number;
21
      name?: string;
22
      description?: string;
23
      quantity_adjusted: number;
24
      item_total?: number;
25
      unit?: string;
26
      is_combo_product?: false | true;
27
      adjustment_account_id?: number;
28
      adjustment_account_name?: string;
29
      location_id?: string;
30
    }[];
31
  },
32
) {
33
  const url = new URL(
34
    `https://www.zohoapis.com/inventory/v1/inventoryadjustments`,
35
  );
36
  for (const [k, v] of [["organization_id", organization_id]]) {
37
    if (v !== undefined && v !== "" && k !== undefined) {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "POST",
43
    headers: {
44
      "Content-Type": "application/json",
45
      Authorization: "Zoho-oauthtoken " + auth.token,
46
    },
47
    body: JSON.stringify(body),
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55