0

Convert lead

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
/**
7
 * Convert lead
8
 * Converts a lead into contact/account/deal using Zoho CRM API v8
9
 */
10
export async function main(
11
  auth: Zoho,
12
  lead_id: string,
13
  body: {
14
    overwrite?: boolean;
15
    notify_lead_owner?: boolean;
16
    notify_new_entity_owner?: boolean;
17
    accounts?: { id?: string };
18
    contacts?: { id?: string };
19
    deals?: {
20
      deal_name: string;
21
      stage: string;
22
      amount?: number;
23
      closing_date?: string;
24
    };
25
  }
26
) {
27
  const url = new URL(
28
    `https://www.zohoapis.com/crm/v8/Leads/${lead_id}/actions/convert`
29
  );
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Zoho-oauthtoken " + auth.token,
36
    },
37
    body: JSON.stringify({ data: [body] }),
38
  });
39

40
  if (!response.ok) {
41
    const text = await response.text();
42
    console.error("Zoho CRM Lead Conversion Error:", text);
43
    throw new Error(`${response.status} ${text}`);
44
  }
45

46
  return await response.json();
47
}
48

49