-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequests.py
More file actions
161 lines (124 loc) · 5.96 KB
/
Copy pathRequests.py
File metadata and controls
161 lines (124 loc) · 5.96 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import requests
import json
from dict2xml import dict2xml as xmlify
import html
import hmac
import hashlib
import base64
#Set Variables
CustomerId = 'ebab41e1-dc5a-4dfa-aa05-5c900cb839e8'
APIUrl ='https://smartconnectschedule.azurewebsites.net/API'
email = ''
password = ''
#Not needed for all endpoints
mapKey = '364fde19-0748-4d10-886f-a95300a506c5'
#Encode Password
def PasswordEncode():
encodedpass = (password + ':6clDgmNok3WtR8GKYW6N').encode('utf-8')
digest = hmac.new(b'6clDgmNok3WtR8GKYW6N', msg=encodedpass, digestmod=hashlib.sha256).digest()
return base64.b64encode(digest).decode()
#Retrieve an auth token from the SmartConnect server
def GetToken():
url = APIUrl + "/GetToken"
params = {'email': email,
'password': PasswordEncode(),
'companyID': CustomerId}
response = requests.post(url, params = params)
return response.text.replace('"','')
#Response Message Handler for map runs
def MessageHandler(response):
if response["Status"] == 0:
print('Run Number ' + str(response["RunNumber"]) + ' of map ' + response["MapId"] + ' Completed successfully')
else:
print('Run Number ' + str(response["RunNumber"]) + ' of map ' + response["MapId"] + ' Completed Unsuccessfully \nErrors: \n' + html.unescape(response["Errors"]))
#Retrieve a list of maps setup in SmartConnect
def GetMapList():
url = APIUrl + "/GetMapList"
params = {'token': GetToken()}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params)
#Format and print response
print(json.dumps(json.loads(response.text), indent=4, sort_keys=True))
#Return a list of columns that were mapped in the integration process of a particular process
def GetMappedMapColumns():
url = APIUrl + "/GetMappedMapColumns"
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params)
print(response.text)
#Get all data from the currently defined data source of a map as an XML data set
def GetAllData():
url = APIUrl + "/GetAllData"
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/xml'}
response = requests.post(url, headers=headers, params = params)
print(html.unescape(response.text))
#Get all data from the currently defined data source of a map using global variables as filters
def GetAllDataWithVariables():
url = APIUrl + "/GetAllDataWithVariables"
variablset = [{"Key":"GBL_TEST","Value":"Test"}, {"Key":"GBL_TEST2","Value":"Test2"}]
payload = json.dumps(variablset)
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/json',
'Accept': 'application/xml'}
response = requests.post(url, headers=headers, params = params, data = payload)
print(html.unescape(response.text))
#Run a map while providing an XML data table
def runmapdatatable():
url = APIUrl + "/RunMapDataTableWithErrors"
dataset = [{"PostingDate":"9/16/2018","Batch":"ETHA","DocumentNo":"Test001","AccountType":"G_L_Account","AccountNo":"20100","AccountDescription":"Accounts Payable","Amount":"50"},
{"PostingDate":"9/16/2018","Batch":"ETHA","DocumentNo":"Test001","AccountType":"G_L_Account","AccountNo":"10500","AccountDescription":"Prepaid Rent","Amount":"60"}]
payload = '<RequestData> \n' + xmlify(dataset, wrap="Table") + '\n</RequestData>'
#print(payload)
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/xml',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params, data = payload)
res = json.loads(response.text)
MessageHandler(res)
#Run a map while providing an XML data table
def runmapxml():
url = APIUrl + "/runmapxml"
#Sample Data Set as List
dataset = [{"PostingDate":"9/16/2018","Batch":"ETHAN","DocumentNo":"Test001","AccountType":"G_L_Account","AccountNo":"20100","AccountDescription":"Accounts Payable","Amount":"50"},
{"PostingDate":"9/16/2018","Batch":"ETHAN","DocumentNo":"Test001","AccountType":"G_L_Account","AccountNo":"10500","AccountDescription":"Prepaid Rent","Amount":"60"}]
#Encode the XML payload
XMLData = '<DataSet>\n' + xmlify(dataset, wrap="Table") + '\n</DataSet>'
payload = '<RequestData>' + '\n<Xml>' + html.escape(XMLData) + '\n</Xml>' + '\n</RequestData>'
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'text/xml',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params, data = payload)
res = json.loads(response.text)
MessageHandler(res)
#Run a process with the currently defined data source in SmartConnect
def RunMap():
url = APIUrl + "/runmap"
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params)
res = json.loads(response.text)
MessageHandler(res)
#Run a process with the currently defined data source in SmartConnect and provide variables
def RunMapWithVariables():
url = APIUrl + "/RunMapWithVariables"
variablset = [{"Key":"GBL_TEST","Value":"Test"}, {"Key":"GBL_TEST2","Value":"Test2"}]
payload = json.dumps(variablset)
params = {'token': GetToken(),
'mapKey': mapKey}
headers = {'Content-Type': 'application/json',
'Accept': 'application/json'}
response = requests.post(url, headers=headers, params = params, data = payload)
res = json.loads(response.text)
MessageHandler(res)
GetMapList()