Edits history of script submission #21174 for ' Convert lead (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    
    /**
     * Convert lead
     * Converts a lead into contact/account/deal using Zoho CRM API v8
     */
    export async function main(
      auth: Zoho,
      lead_id: string,
      body: {
        overwrite?: boolean;
        notify_lead_owner?: boolean;
        notify_new_entity_owner?: boolean;
        accounts?: { id?: string };
        contacts?: { id?: string };
        deals?: {
          deal_name: string;
          stage: string;
          amount?: number;
          closing_date?: string;
        };
      }
    ) {
      const url = new URL(
        `https://www.zohoapis.com/crm/v8/Leads/${lead_id}/actions/convert`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify({ data: [body] }),
      });
    
      if (!response.ok) {
        const text = await response.text();
        console.error("Zoho CRM Lead Conversion Error:", text);
        throw new Error(`${response.status} ${text}`);
      }
    
      return await response.json();
    }
    
    

    Submitted by hugo697 235 days ago