Edits history of script submission #21030 for ' Business Match (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Business Match
     * This endpoint lets you match business data from other sources against businesses on Yelp, based on provided business information.
     */
    export async function main(
      auth: Yelp,
      name: string | undefined,
      address1: string | undefined,
      address2: string | undefined,
      address3: string | undefined,
      city: string | undefined,
      state: string | undefined,
      country: string | undefined,
      postal_code: string | undefined,
      latitude: string | undefined,
      longitude: string | undefined,
      phone: string | undefined,
      yelp_business_id: string | undefined,
      limit: string | undefined,
      match_threshold: "none" | "default" | "strict" | undefined,
    ) {
      const url = new URL(`https://api.yelp.com/v3/businesses/matches`);
      for (const [k, v] of [
        ["name", name],
        ["address1", address1],
        ["address2", address2],
        ["address3", address3],
        ["city", city],
        ["state", state],
        ["country", country],
        ["postal_code", postal_code],
        ["latitude", latitude],
        ["longitude", longitude],
        ["phone", phone],
        ["yelp_business_id", yelp_business_id],
        ["limit", limit],
        ["match_threshold", match_threshold],
      ]) {
        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.json();
    }
    

    Submitted by hugo697 235 days ago