0
Get IP Details
One script reply has been approved by the moderators Verified

Determines the location and other details of an IP address.

Created by hugo697 56 days ago Viewed 13 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 56 days ago
1
type Abstractapi = {
2
	apiKey: string
3
}
4

5
export async function main(resource: Abstractapi, ipAddress?: string) {
6
	const queryParams = new URLSearchParams({
7
		api_key: resource.apiKey
8
	})
9

10
	if (ipAddress) {
11
		queryParams.append('ip_address', ipAddress)
12
	}
13

14
	const endpoint = `https://ipgeolocation.abstractapi.com/v1?${queryParams.toString()}`
15

16
	const response = await fetch(endpoint, {
17
		method: 'GET'
18
	})
19

20
	if (!response.ok) {
21
		throw new Error(`HTTP error! status: ${response.status}`)
22
	}
23

24
	const data = await response.json()
25

26
	return data
27
}
28