Edits history of script submission #19961 for ' List contacts (salesflare)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Salesflare = {
      apiKey: string;
    };
    /**
     * List contacts
     *
     */
    export async function main(
      auth: Salesflare,
      id: string | undefined,
      name: string | undefined,
      email: string | undefined,
      phone_number: string | undefined,
      domain: string | undefined,
      modification_after: string | undefined,
      modification_before: string | undefined,
      creation_after: string | undefined,
      creation_before: string | undefined,
      account: string | undefined,
      tag: string | undefined,
      tag_name: string | undefined,
      position_role: string | undefined,
      address_country: string | undefined,
      address_state_region: string | undefined,
      address_city: string | undefined,
      includeArchived: string | undefined,
      search: string | undefined,
      _type: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
      custom: string | undefined,
      order_by: string | undefined,
      _export: string | undefined,
      q: string | undefined,
    ) {
      const url = new URL(`https://api.salesflare.com/contacts`);
      for (const [k, v] of [
        ["id", id],
        ["name", name],
        ["email", email],
        ["phone_number", phone_number],
        ["domain", domain],
        ["modification_after", modification_after],
        ["modification_before", modification_before],
        ["creation_after", creation_after],
        ["creation_before", creation_before],
        ["account", account],
        ["tag", tag],
        ["tag.name", tag_name],
        ["position.role", position_role],
        ["address.country", address_country],
        ["address.state_region", address_state_region],
        ["address.city", address_city],
        ["includeArchived", includeArchived],
        ["search", search],
        ["type", _type],
        ["limit", limit],
        ["offset", offset],
        ["custom", custom],
        ["order_by", order_by],
        ["export", _export],
        ["q", q],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago