0

Add Additional Address

by
Published Oct 17, 2025

Add an additional address for a contact using the arguments below.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Add Additional Address
7
 * Add an additional address for a contact using the arguments below.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  contact_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    attention?: string;
15
    address?: string;
16
    street2?: string;
17
    city?: string;
18
    state?: string;
19
    zip?: string;
20
    country?: string;
21
    fax?: string;
22
    phone?: string;
23
  },
24
) {
25
  const url = new URL(
26
    `https://www.zohoapis.com/books/v3/contacts/${contact_id}/address`,
27
  );
28
  for (const [k, v] of [["organization_id", organization_id]]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "POST",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Zoho-oauthtoken " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47