-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add contact imports endpoints #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6880d7c
feat: add contact imports endpoints
drish 2f4c8de
fix: mypy type errors in contact imports
drish d0ce8d6
feat: add contact imports example
drish e200bb3
feat: add topics to CreateParams and use contacts.csv in example
drish 37f21f5
chore: update topic id in contact imports example
drish e8dda2c
chore: update topic id and add timestamp to contact imports example
drish a386f62
fix: use NotRequired for counts, remove duplicate status param, guard…
drish 96e8f9b
fix: pass data in non-multipart requests and tighten error assertions…
drish 0fbe4ef
refactor: extract _build_multipart helper and fix json/data mutual ex…
drish 30e0c8d
fix: use Tuple from typing for py3.7 compat in _build_multipart retur…
drish cee0650
fix: add completed_at, fix contacts __init__ alias, forward files/dat…
drish 99a0e69
refactor: use resend.Contacts.Imports.* type access pattern in exampl…
drish 6350c89
refactor: expose ContactImport on ContactImports class for consistent…
drish dc4ce98
fix: use direct class refs for type annotations, matching ContactSegm…
drish 2380c5f
chore: bump version to 2.31.0 (#221)
drish 1dbed3e
chore: bump version to 2.32.0
drish 3d31f4d
Merge branch 'main' into feat/contact-imports
drish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import os | ||
|
|
||
| import resend | ||
|
|
||
| if not os.environ["RESEND_API_KEY"]: | ||
| raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
|
||
| file_content = b"Email,First Name,Last Name,Plan\nsteve@example.com,Steve,Wozniak,pro" | ||
|
|
||
| create_params: resend.ContactImports.CreateParams = { | ||
| "file": file_content, | ||
| "column_map": { | ||
| "email": "Email", | ||
| "first_name": "First Name", | ||
| "last_name": "Last Name", | ||
| "properties": { | ||
| "plan": { | ||
| "column": "Plan", | ||
| "type": "string", | ||
| }, | ||
| }, | ||
| }, | ||
| "on_conflict": "upsert", | ||
| "segments": ["60a2ac5e-0774-456e-817d-ebf40f6dba31"], | ||
| } | ||
|
|
||
| import_response: resend.ContactImports.CreateContactImportResponse = ( | ||
| resend.Contacts.Imports.create(create_params) | ||
| ) | ||
| print("Created contact import with ID: {}".format(import_response["id"])) | ||
| print(import_response) | ||
|
|
||
| contact_import: resend.ContactImport = resend.Contacts.Imports.get(import_response["id"]) | ||
| print("Retrieved contact import") | ||
| print(contact_import) | ||
|
|
||
| list_response: resend.ContactImports.ListContactImportsResponse = ( | ||
| resend.Contacts.Imports.list() | ||
| ) | ||
| print(f"Found {len(list_response['data'])} imports") | ||
| print(f"Has more: {list_response['has_more']}") | ||
| for item in list_response["data"]: | ||
| print(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from .imports._contact_import import ContactImport as ContactImportObj | ||
| from .imports._contact_import import ContactImportCounts | ||
| from .imports._contact_imports import ContactImports | ||
|
|
||
| __all__ = ["ContactImports", "ContactImportObj", "ContactImportCounts"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from ._contact_import import ContactImport, ContactImportCounts | ||
| from ._contact_imports import ContactImports | ||
|
|
||
| __all__ = ["ContactImports", "ContactImport", "ContactImportCounts"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from typing import Optional | ||
|
|
||
| from resend._base_response import BaseResponse | ||
|
|
||
|
|
||
| class ContactImportCounts(BaseResponse): | ||
| """ | ||
| ContactImportCounts holds row-level statistics for a contact import. | ||
|
|
||
| Attributes: | ||
| total (int): Total number of rows processed. | ||
| created (int): Number of contacts created. | ||
| updated (int): Number of contacts updated. | ||
| skipped (int): Number of rows skipped. | ||
| failed (int): Number of rows that failed. | ||
| """ | ||
|
|
||
| total: int | ||
| created: int | ||
| updated: int | ||
| skipped: int | ||
| failed: int | ||
|
|
||
|
|
||
| class ContactImport(BaseResponse): | ||
| """ | ||
| ContactImport represents a contact import job. | ||
|
|
||
| Attributes: | ||
| object (str): Always 'contact_import'. | ||
| id (str): Unique identifier for the contact import. | ||
| status (str): 'queued', 'in_progress', 'completed', or 'failed'. | ||
| created_at (str): ISO 8601 timestamp of when the import was created. | ||
| counts (ContactImportCounts): Row-level import statistics (present when status is completed or failed). | ||
| """ | ||
|
|
||
| object: str | ||
| id: str | ||
| status: str | ||
| created_at: str | ||
| counts: Optional[ContactImportCounts] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.