|
| 1 | +import os |
| 2 | +import time |
| 3 | + |
| 4 | +import resend |
| 5 | + |
| 6 | +if not os.environ["RESEND_API_KEY"]: |
| 7 | + raise EnvironmentError("RESEND_API_KEY is missing") |
| 8 | + |
| 9 | +ts = int(time.time()) |
| 10 | +csv_path = os.path.join(os.path.dirname(__file__), "contacts.csv") |
| 11 | +with open(csv_path, "rb") as f: |
| 12 | + file_content = f.read().replace(b"steve@example.com,Steve,Wozniak", f"steve+{ts}@example.com,Steve,Wozniak".encode()) |
| 13 | + |
| 14 | +create_params: resend.ContactImports.CreateParams = { |
| 15 | + "file": file_content, |
| 16 | + "column_map": { |
| 17 | + "email": "Email", |
| 18 | + "first_name": "First Name", |
| 19 | + "last_name": "Last Name", |
| 20 | + "properties": { |
| 21 | + "plan": { |
| 22 | + "column": "Plan", |
| 23 | + "type": "string", |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + "on_conflict": "upsert", |
| 28 | + "segments": ["60a2ac5e-0774-456e-817d-ebf40f6dba31"], |
| 29 | + "topics": [ |
| 30 | + { |
| 31 | + "id": "6eb54030-9489-4e9c-8de6-cd337c5fef1e", |
| 32 | + "subscription": "opt_in", |
| 33 | + }, |
| 34 | + ], |
| 35 | +} |
| 36 | + |
| 37 | +import_response: resend.ContactImports.CreateContactImportResponse = ( |
| 38 | + resend.Contacts.Imports.create(create_params) |
| 39 | +) |
| 40 | +print("Created contact import with ID: {}".format(import_response["id"])) |
| 41 | +print(import_response) |
| 42 | + |
| 43 | +contact_import: resend.ContactImport = resend.Contacts.Imports.get(import_response["id"]) |
| 44 | +print("Retrieved contact import") |
| 45 | +print(contact_import) |
| 46 | + |
| 47 | +list_response: resend.ContactImports.ListContactImportsResponse = ( |
| 48 | + resend.Contacts.Imports.list() |
| 49 | +) |
| 50 | +print(f"Found {len(list_response['data'])} imports") |
| 51 | +print(f"Has more: {list_response['has_more']}") |
| 52 | +for item in list_response["data"]: |
| 53 | + print(item) |
0 commit comments