-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontact_fields.py
More file actions
66 lines (47 loc) · 1.69 KB
/
contact_fields.py
File metadata and controls
66 lines (47 loc) · 1.69 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
57
58
59
60
61
62
63
64
65
66
from typing import Optional
import mailtrap as mt
from mailtrap.models.common import DeletedObject
from mailtrap.models.contacts import ContactField
API_TOKEN = "YOUR_API_TOKEN"
ACCOUNT_ID = "YOUR_ACCOUNT_ID"
client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID)
contact_fields_api = client.contacts_api.contact_fields
def create_contact_field(
name: str,
data_type: str,
merge_tag: str,
) -> ContactField:
params = mt.CreateContactFieldParams(
name=name,
data_type=data_type,
merge_tag=merge_tag,
)
return contact_fields_api.create(params)
def update_contact_field(
contact_field_id: int,
name: Optional[str] = None,
merge_tag: Optional[str] = None,
) -> ContactField:
params = mt.UpdateContactFieldParams(name=name, merge_tag=merge_tag)
return contact_fields_api.update(contact_field_id, params)
def list_contact_fields() -> list[ContactField]:
return contact_fields_api.get_list()
def get_contact_field(contact_field_id: int) -> ContactField:
return contact_fields_api.get_by_id(contact_field_id)
def delete_contact_field(contact_field_id: int) -> DeletedObject:
return contact_fields_api.delete(contact_field_id)
if __name__ == "__main__":
created = create_contact_field(
name="example_field", data_type="string", merge_tag="EXAMPLE"
)
print(created)
fields = list_contact_fields()
print(fields)
field = get_contact_field(contact_field_id=created.id)
print(field)
updated = update_contact_field(
contact_field_id=created.id, name=f"{field.name}-updated"
)
print(updated)
deleted = delete_contact_field(contact_field_id=created.id)
print(deleted)