0

Validate email

by
Published Apr 8, 2025

This endpoint will let you check if the e-mail address sent in query is valid.

Script foxentry Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Foxentry = {
3
  apiKey: string;
4
};
5
/**
6
 * Validate email
7
 * This endpoint will let you check if the e-mail address sent in query is valid.
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: { email: string };
17
      options?: {
18
        validationType?: "basic" | "extended";
19
        acceptDisposableEmails?: false | true;
20
        acceptFreemails?: false | true;
21
      };
22
      client?: {
23
        ip?: string;
24
        country?: string;
25
        location?: { lat?: number; lon?: number };
26
      };
27
    };
28
  },
29
) {
30
  const url = new URL(`https://api.foxentry.com/email/validate`);
31

32
  const headers: Record<string, string> = {
33
    "Content-Type": "application/json",
34
    Authorization: "Bearer " + auth.apiKey,
35
  };
36

37
  if (api_version) {
38
    headers["api-version"] = api_version;
39
  }
40
  if (foxentry_include_request_details) {
41
    headers["foxentry-include-request-details"] = foxentry_include_request_details;
42
  }
43

44
  const response = await fetch(url, {
45
    method: "POST",
46
    headers,
47
    body: JSON.stringify(body),
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55