0

Delete record

by
Published Oct 17, 2025
Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Delete record
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  module_api_name: string,
12
  id: string,
13
  wf_trigger: string | undefined,
14
  X_EXTERNAL?: string,
15
) {
16
  const url = new URL(`https://zohoapis.com/crm/v8/${module_api_name}/${id}`);
17
  for (const [k, v] of [["wf_trigger", wf_trigger]]) {
18
    if (v !== undefined && v !== "" && k !== undefined) {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "DELETE",
24
    headers: {
25
      ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}),
26
      Authorization: "Zoho-oauthtoken " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36