0

Update a Purchase Receive

by
Published Oct 17, 2025

Update a existing Purchase Receive from 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
 * Update a Purchase Receive
7
 * Update a existing Purchase Receive from Zoho Inventory.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  purchasereceive_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    receive_number: string;
15
    date?: string;
16
    notes?: string;
17
    custom_fields?: { customfield_id?: number; value?: string }[];
18
    line_items: {
19
      line_item_id?: number;
20
      item_id?: number;
21
      name?: string;
22
      description?: string;
23
      item_order?: number;
24
      quantity?: number;
25
      unit?: string;
26
    }[];
27
  },
28
) {
29
  const url = new URL(
30
    `https://www.zohoapis.com/inventory/v1/purchasereceives/${purchasereceive_id}`,
31
  );
32
  for (const [k, v] of [["organization_id", organization_id]]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "PUT",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Zoho-oauthtoken " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51