Edits history of script submission #21261 for ' Create zia org enrichment (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create zia org enrichment
     *
     */
    export async function main(
      auth: Zoho,
      _module: string | undefined,
      record_id: string | undefined,
      body: {
        __zia_org_enrichment: {
          enriched_data?: {
            org_status?: string;
            description?: { title?: string; description?: string }[];
            ceo?: string;
            secondary_email?: string;
            revenue?: string;
            years_in_industry?: string;
            other_contacts?: string[];
            techno_graphic_data?: string;
            logo?: string;
            secondary_contact?: string;
            id?: string;
            other_emails?: string[];
            sign_in?: string;
            website?: string;
            address?: {
              country: string;
              city: string;
              pin_code: string;
              state: string;
              fill_address: string;
            }[];
            sign_up?: string;
            org_type?: string;
            head_quarters?: {
              country: string;
              city: string;
              pin_code: string;
              state: string;
              fill_address: string;
            }[];
            no_of_employees?: string;
            territory_list?: string[];
            founding_year?: string;
            industries?: { name?: string; description?: string }[];
            name?: string;
            primary_email?: string;
            business_model?: string[];
            primary_contact?: string;
            social_media?: { media_type: string; media_url: string[] }[];
          };
          created_time: string;
          id: string;
          created_by: { name: string; id: string };
          status: string;
          enrich_based_on: { name: string; email?: string; website?: string };
        }[];
      },
    ) {
      const url = new URL(`https://zohoapis.com/crm/v8/__zia_org_enrichment`);
      for (const [k, v] of [
        ["module", _module],
        ["record_id", record_id],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago