Skip to content

Commit d0ce8d6

Browse files
committed
feat: add contact imports example
1 parent 2f4c8de commit d0ce8d6

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

examples/contact_imports.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
3+
import resend
4+
5+
if not os.environ["RESEND_API_KEY"]:
6+
raise EnvironmentError("RESEND_API_KEY is missing")
7+
8+
file_content = b"Email,First Name,Last Name,Plan\nsteve@example.com,Steve,Wozniak,pro"
9+
10+
create_params: resend.ContactImports.CreateParams = {
11+
"file": file_content,
12+
"column_map": {
13+
"email": "Email",
14+
"first_name": "First Name",
15+
"last_name": "Last Name",
16+
"properties": {
17+
"plan": {
18+
"column": "Plan",
19+
"type": "string",
20+
},
21+
},
22+
},
23+
"on_conflict": "upsert",
24+
"segments": ["60a2ac5e-0774-456e-817d-ebf40f6dba31"],
25+
}
26+
27+
import_response: resend.ContactImports.CreateContactImportResponse = (
28+
resend.Contacts.Imports.create(create_params)
29+
)
30+
print("Created contact import with ID: {}".format(import_response["id"]))
31+
print(import_response)
32+
33+
contact_import: resend.ContactImport = resend.Contacts.Imports.get(import_response["id"])
34+
print("Retrieved contact import")
35+
print(contact_import)
36+
37+
list_response: resend.ContactImports.ListContactImportsResponse = (
38+
resend.Contacts.Imports.list()
39+
)
40+
print(f"Found {len(list_response['data'])} imports")
41+
print(f"Has more: {list_response['has_more']}")
42+
for item in list_response["data"]:
43+
print(item)

0 commit comments

Comments
 (0)