-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdomains_async.py
More file actions
56 lines (43 loc) · 1.52 KB
/
domains_async.py
File metadata and controls
56 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import asyncio
import os
import resend
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")
# Set up async HTTP client
resend.default_http_client = resend.HTTPXClient()
async def main() -> None:
create_params: resend.Domains.CreateParams = {
"name": "example.com",
"region": "us-east-1",
"custom_return_path": "outbound",
}
domain: resend.Domains.CreateDomainResponse = await resend.Domains.create_async(
params=create_params
)
print(domain)
retrieved: resend.Domain = await resend.Domains.get_async(domain_id=domain["id"])
if retrieved["records"] is not None:
for record in retrieved["records"]:
print(record)
update_params: resend.Domains.UpdateParams = {
"id": domain["id"],
"open_tracking": True,
"click_tracking": True,
"tls": "enforced",
}
updated_domain: resend.Domain = await resend.Domains.update_async(update_params)
print(f"Updated domain: {updated_domain['id']}")
domains: resend.Domains.ListResponse = await resend.Domains.list_async()
if not domains:
print("No domains found")
for d in domains["data"]:
print(d)
verified_domain: resend.Domain = await resend.Domains.verify_async(
domain_id=domain["id"]
)
print("Verified")
print(verified_domain)
rm_domain: resend.Domain = await resend.Domains.remove_async(domain_id=domain["id"])
print(rm_domain)
if __name__ == "__main__":
asyncio.run(main())