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

Check the status of a specified VAT number.

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

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

11
	const endpoint = `https://vat.abstractapi.com/v1/validate?${queryParams.toString()}`
12

13
	const response = await fetch(endpoint, {
14
		method: 'GET'
15
	})
16

17
	if (!response.ok) {
18
		throw new Error(`HTTP error! status: ${response.status}`)
19
	}
20

21
	const data = await response.json()
22

23
	return data
24
}
25