Edits history of script submission #21901 for ' Retrieve a customer Using CRM Reference (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Retrieve a customer Using CRM Reference
     * Details of an existing customer using CRM Reference ID. reference_id can be  CRM Contact ID  (for Contacts only sync) or  CRM Account ID  (For accounts only and Accounts and its contacts sync). Query param value of  reference_id_type  must be given accoridngly.
     */
    export async function main(
      auth: Zoho,
      reference_id: string,
      reference_id_type: string | undefined,
      X_com_zoho_subscriptions_organizationid: string,
    ) {
      const url = new URL(
        `https://www.zohoapis.com/billing/v1/customers/reference/${reference_id}`,
      );
      for (const [k, v] of [["reference_id_type", reference_id_type]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "X-com-zoho-subscriptions-organizationid":
            X_com_zoho_subscriptions_organizationid,
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago