Edits history of script submission #12188 for ' Validate phone numbers and retrieve additional information (greip)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Greip = {
      apiKey: string;
    };
    /**
     * Validate phone numbers and retrieve additional information
     * This method serves as an additional layer of protection in your system for validating phone numbers. It not only checks the syntax but also assesses the likelihood of the phone number being valid and operational.
    
    By incorporating this scoring into your workflow, you can enhance fraud detection, reduce invalid inputs, and improve the overall quality of data captured.
     */
    export async function main(
      auth: Greip,
      phone: string,
      countryCode: string | undefined,
      format: string | undefined,
      userID: string | undefined,
      mode: string | undefined,
      callback: string | undefined,
    ) {
      const url = new URL(`https://greipapi.com/scoring/phone`);
      for (const [k, v] of [
        ["phone", phone],
        ["countryCode", countryCode],
        ["format", format],
        ["userID", userID],
        ["mode", mode],
        ["callback", callback],
      ]) {
        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 428 days ago