0

Get location data

by
Published Apr 8, 2025

Foxentry allows you to get information about location based on the dataScope option. Country and ID parameters are required. You can either choose internal ID, which is assigned by Foxentry or external ID from the data source. CZ external = RUIAN, PL external = Gov data, SK external does not exist.

Script foxentry Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Foxentry = {
3
  apiKey: string;
4
};
5
/**
6
 * Get location data
7
 * Foxentry allows you to get information about location based on the dataScope option. Country and ID parameters are required. You can either choose internal ID, which is assigned by Foxentry or external ID from the data source. CZ external = RUIAN, PL external = Gov data, SK external does not exist.
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: { country: string; id: string };
17
      options?: {
18
        dataScope?: "basic" | "full";
19
        dataSource?: string[];
20
        zipFormat?: false | true;
21
        countryFormat?:
22
          | "alpha2"
23
          | "alpha3"
24
          | "local"
25
          | "localShortened"
26
          | "international"
27
          | "internationalShortened";
28
        cityFormat?: "basic" | "minimal" | "extended";
29
      } & { idType?: "internal" | "external" };
30
      client?: {
31
        ip?: string;
32
        country?: string;
33
        location?: { lat?: number; lon?: number };
34
      };
35
    };
36
  },
37
) {
38
  const url = new URL(`https://api.foxentry.com/location/get`);
39

40
  const headers: Record<string, string> = {
41
    "Content-Type": "application/json",
42
    Authorization: "Bearer " + auth.apiKey,
43
  };
44

45
  if (api_version) {
46
    headers["api-version"] = api_version;
47
  }
48
  if (foxentry_include_request_details) {
49
    headers["foxentry-include-request-details"] = foxentry_include_request_details;
50
  }
51

52
  const response = await fetch(url, {
53
    method: "POST",
54
    headers,
55
    body: JSON.stringify(body),
56
  });
57
  if (!response.ok) {
58
    const text = await response.text();
59
    throw new Error(`${response.status} ${text}`);
60
  }
61
  return await response.json();
62
}
63