Edits history of script submission #12165 for ' Localization (foxentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Foxentry = {
      apiKey: string;
    };
    /**
     * Localization
     * Foxentry allows you to check an area with GPS radius in order to return all the addresses within that area. It can also give you additional information about the addresses based on the dataScope option.Please pay attention to the singleLocationResultDistance option, which determines the radius of the search area in meters.
     */
    export async function main(
      auth: Foxentry,
      api_version: string | undefined,
      foxentry_include_request_details: string | undefined,
      body: {
        request: {
          customId?: string;
          query: { lat: number; lon: number };
          options?: {
            dataScope?: "basic" | "full";
            dataSource?: string[];
            zipFormat?: false | true;
            countryFormat?:
              | "alpha2"
              | "alpha3"
              | "local"
              | "localShortened"
              | "international"
              | "internationalShortened";
            cityFormat?: "basic" | "minimal" | "extended";
          } & { radius?: number; acceptNearest?: false | true };
          client?: { ip?: string; country?: string };
        };
      },
    ) {
      const url = new URL(`https://api.foxentry.com/location/localize`);
    
      const headers: Record<string, string> = {
        "Content-Type": "application/json",
        Authorization: "Bearer " + auth.apiKey,
      };
    
      if (api_version) {
        headers["api-version"] = api_version;
      }
      if (foxentry_include_request_details) {
        headers["foxentry-include-request-details"] = foxentry_include_request_details;
      }
    
      const response = await fetch(url, {
        method: "POST",
        headers,
        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 428 days ago