0
Validate Phone
One script reply has been approved by the moderators Verified

Check the status of a specified phone number.

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

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

11
	if (countryCode) {
12
		queryParams.append('country', countryCode)
13
	}
14

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

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

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

25
	const data = await response.json()
26

27
	return data
28
}
29