forked from cuenca-mx/facturapi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomers.py
More file actions
39 lines (30 loc) · 1.06 KB
/
Copy pathcustomers.py
File metadata and controls
39 lines (30 loc) · 1.06 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
import facturapi
from facturapi.resources.customers import (
CustomerRequest,
CustomerUpdateRequest,
)
def main():
# Create a customer by filling a CustomerRequest
customer_request = CustomerRequest(
legal_name='John Doe',
tax_id='ABCD111111CBA',
email='email@example.com',
)
customer = facturapi.Customer.create(data=customer_request)
# Access to data or perform updates
tax_id = customer.tax_id
update_request = CustomerUpdateRequest(email='email2@example.net')
updated_customer = facturapi.Customer.update(
id=customer.id, data=update_request
)
assert updated_customer.email != customer.email
# Retrieve customer by ID
retrieved_customer = facturapi.Customer.retrieve('some_id')
# Perform queries to retrieve by specific values:
lots_of_customers = facturapi.Customer.all(limit=20)
for customer in lots_of_customers:
# Iterate through results and use them as resources:
c_id = customer.id
name = customer.name
if __name__ == '__main__':
main()