0

Create a contact person

by
Published Oct 17, 2025

Create a contact person for contact.

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 contact person
7
 * Create a contact person for contact.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  body: {
13
    contact_id?: string;
14
    salutation?: string;
15
    first_name: string;
16
    last_name?: string;
17
    email?: string;
18
    phone?: string;
19
    mobile?: string;
20
    skype?: string;
21
    designation?: string;
22
    department?: string;
23
    enable_portal?: false | true;
24
  },
25
) {
26
  const url = new URL(
27
    `https://www.zohoapis.com/inventory/v1/contacts/contactpersons`,
28
  );
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