-
Notifications
You must be signed in to change notification settings - Fork 0
/
sevDesk.py
142 lines (116 loc) · 4.63 KB
/
sevDesk.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
https://my.sevdesk.de/swaggerUI/index.html
https://my.sevdesk.de/swaggerJSON/swagger.json
"""
import requests
import json
def get_phone_mail_from_communications(communications, customer_id):
phone = None
mail = None
more_data = None
status = True
for c in communications:
if c['contact']['id'] == customer_id:
if c['key']['id'] == '2':
if c['type'] == 'PHONE':
phone = c['value']
elif c['type'] == 'EMAIL':
mail = c['value']
more_data = c
if phone != None:
# I use a +49 (for germany) 1... (for cellphone numbers)
# may be different for your purpose
if phone[3] != '1':
# TODO: more info here on customer number or name.
print(f'please check the customer with number {phone}, {mail}')
print(more_data)
print('this does not seem like a phone number to me')
status = False
return phone, mail, status
class sevDesk:
def __init__(self, email, token):
self.base_url = 'https://my.sevdesk.de/api/v1/'
self.email = email
self.token = token
self.headers = {'Authorization': self.token}
"""
doc: https://my.sevdesk.de/swaggerUI/index.html#/Contact/getContacts
"""
def get_contacts(self, depth=1, limit=9999, offset=0):
url = self.base_url + f'Contact/?depth={depth}&limit={limit}&offset={offset}'
response = requests.get(url, headers=self.headers)
data = json.loads(response.content)
return data['objects']
def get_contact_address(self, id_contact):
url = self.base_url + f'Contact/{id_contact}/getAddresses'
response = requests.get(url, headers=self.headers)
# print(response)
data = json.loads(response.content)
# print(data)
return data['objects']
def get_contact_mail(self, id_contact):
print('get_contact_mail is deprecated for get_communication_ways')
url = self.base_url + f'Contact/{id_contact}/getMainEmail'
response = requests.get(url, headers=self.headers)
data = json.loads(response.content)
_mail = data['objects']
if _mail != None:
return _mail['value']
else:
return None
def get_communication_ways(self, limit=9999):
url = self.base_url + f'CommunicationWay/?limit={limit}'
response = requests.get(url, headers=self.headers)
data = json.loads(response.content)
return data['objects']
def get_contact_phone(self, id_contact):
print('get_contact_phone is deprecated for get_communication_ways')
url = self.base_url + f'Contact/{id_contact}/getMainPhone'
response = requests.get(url, headers=self.headers)
print(response.content)
data = json.loads(response.content)
_phone = data['objects']
if _phone != None:
return _phone['value']
else:
return None
"""
doc: https://my.sevdesk.de/swaggerUI/index.html#/Contact/addContact
"""
def add_contact_person(self, name, customerNumber, gender, firstname, description):
url = self.base_url + "Contact/"
data = {
'category[id]': 3,
'category[objectName]': 'Category',
'familyname': name,
'customerNumber': customerNumber,
'gender': gender,
'surename': firstname,
'description': description
}
response = requests.post(url, data=data, headers=self.headers)
ret = json.loads(response.content)
return ret['objects']['id']
def add_contact_phone(self, id_contact, phone):
url = self.base_url + f"Contact/{id_contact}/addPhone"
data = {
'key': 1,
'value': phone
}
response = requests.post(url, data=data, headers=self.headers)
def add_contact_email(self, id_contact, email):
url = self.base_url + f"Contact/{id_contact}/addEmail"
data = {
'key': 1,
'value': email
}
response = requests.post(url, data=data, headers=self.headers)
def add_contact_address(self, id_contact, street, zip, city):
url = self.base_url + f"Contact/{id_contact}/addAddress"
data = {
'street': street,
'zip': zip,
'city': city,
'country': '1' # 1 == Germany
}
response = requests.post(url, data=data, headers=self.headers)