forked from dem972/Mosyle_2snipe
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmosyle.py
64 lines (56 loc) · 1.57 KB
/
mosyle.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
import base64
import requests
class Mosyle:
# Create Mosyle instance
def __init__(self, key, url = "https://businessapi.mosyle.com/v1", user = "", password = ""):
# Attribute the variable to the instance
self.url = url
self.request = requests.Session()
self.request.headers["accesstoken"] = key
#base64 encode username and password for basic auth
userpass = user + ':' + password
encoded_u = base64.b64encode(userpass.encode()).decode()
self.request.headers["Authorization"] = "Basic %s" % encoded_u
# Create variables requests
def list(self, os):
print("Listing devices for OS:", os)
params = {
"operation": "list",
"options": {
"os": os
}
}
# Concatanate url and send the request
return self.request.post(self.url + "/devices", json = params )
def listTimestamp(self, start, end, os):
params = {
"operation": "list",
"options": {
"os": os,
"enrolldate_start": start,
"enrolldate_end": end
}
}
return self.request.post(self.url + "/devices", json = params )
def listmobile(self):
params = {
"operation": "list",
"options": {
"os": "ios"
}
}
return self.request.post(self.url + "/devices", json = params )
def listuser(self, iduser):
params = {
"operation": "list_users",
"options": { "identifiers": [iduser]
}
}
return self.request.post(self.url + "/users", json = params )
def setAssetTag(self, serialnumber, tag):
params = {
"operation": "update_device",
"serialnumber": serialnumber,
"asset_tag": tag
}
return self.request.post(self.url + "/devices", json = params )