0

Create a purchase receive

by
Published Oct 17, 2025

A new purchase receive can a be created.To create Purchase receive, URL parameter purchaseorder_id is needed.

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