0

Search location

by
Published Apr 8, 2025

This enpoint mainly serves as autocomplete but can be used to search for specific addresses based on filter criteria as well. Foxentry will automatically offer you suggestions to complete the address you are writing down. Pay attention to the client section in the request body. You can specify the user's location in order to receive more relevant suggestions.

Script foxentry Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Foxentry = {
3
  apiKey: string;
4
};
5
/**
6
 * Search location
7
 * This enpoint mainly serves as autocomplete but can be used to search for specific addresses based on filter criteria as well. Foxentry will automatically offer you suggestions to complete the address you are writing down. Pay attention to the client section in the request body. You can specify the user's location in order to receive more relevant suggestions.
8
 */
9
export async function main(
10
  auth: Foxentry,
11
  api_version: string | undefined,
12
  foxentry_include_request_details: string | undefined,
13
  body: {
14
    request: {
15
      customId?: string;
16
      query: {
17
        type:
18
          | "street"
19
          | "streetWithNumber"
20
          | "number.full"
21
          | "number.part1"
22
          | "number.part2"
23
          | "city"
24
          | "zip"
25
          | "full";
26
        value: string;
27
        filter?: {
28
          street?: string;
29
          streetWithNumber?: string;
30
          "number.full"?: string;
31
          "number.part1"?: string;
32
          "number.part2"?: string;
33
          city?: string;
34
          zip?: string;
35
          country?: string;
36
        };
37
      };
38
      options?: {
39
        dataScope?: "full" | "basic";
40
        dataSource?: string[];
41
        zipFormat?: false | true;
42
        countryFormat?:
43
          | "alpha2"
44
          | "alpha3"
45
          | "local"
46
          | "localShortened"
47
          | "international"
48
          | "internationalShortened";
49
        cityFormat?: "basic" | "minimal" | "extended";
50
      };
51
      client?: {
52
        ip?: string;
53
        country?: string;
54
        location?: { lat?: number; lon?: number };
55
      };
56
    };
57
  },
58
) {
59
  const url = new URL(`https://api.foxentry.com/location/search`);
60

61
  const headers: Record<string, string> = {
62
    "Content-Type": "application/json",
63
    Authorization: "Bearer " + auth.apiKey,
64
  };
65

66
  if (api_version) {
67
    headers["api-version"] = api_version;
68
  }
69
  if (foxentry_include_request_details) {
70
    headers["foxentry-include-request-details"] = foxentry_include_request_details;
71
  }
72

73
  const response = await fetch(url, {
74
    method: "POST",
75
    headers,
76
    body: JSON.stringify(body),
77
  });
78
  if (!response.ok) {
79
    const text = await response.text();
80
    throw new Error(`${response.status} ${text}`);
81
  }
82
  return await response.json();
83
}
84